【发布时间】:2021-09-21 16:02:12
【问题描述】:
import React from "react";
import "./App.css";
function SecretComponent() {
return <p>Secret2 information for authorised users only </p>;
}
function RegularComponent() {
return <p>Everyone1 can see this component</p>;
}
function App(props) {
if (props.authorized) {
return <SecretComponent />;
} else {
return <RegularComponent />;
}
}
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
ReactDOM.render(<App authorized={false} />, document.getElementById("root"));
在我在 Visual Studio Code 中的 react 项目中,当我进行更改时,浏览器页面仅在 App.js 文件中进行更改时刷新,但在 index.js 文件中进行更改时不会刷新。我必须手动刷新页面才能显示更改。
【问题讨论】:
-
你能分享一个回购例子吗?
-
你在用
create-react-app吗? -
npx create-react-app <app-name>我用npm start运行它 -
当我更改
authorized={true}中的值时,我注意到此更改不会在 Bowser 开发组件中传播。授权仍然显示authorised: false,直到我刷新浏览器。页面刷新后,值与代码库同步。
标签: javascript reactjs visual-studio-code