Reactjs 无原因调用两次react组件渲染方法 import'/App.css'; 从“./components/SolarSystem/SolarSystem”导入SolarSystem; 类应用程序扩展了React.Component{ componentDidMount(){ 控制台日志(“安装”); } componentDidUpdate(){ 控制台日志(“更新”); } //const[SSVisibility,setSSVisibility]=useState(true); render(){ console.log(“渲染应用程序”); 返回( SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS {/* */} ); } } 导出默认应用程序;

Reactjs 无原因调用两次react组件渲染方法 import'/App.css'; 从“./components/SolarSystem/SolarSystem”导入SolarSystem; 类应用程序扩展了React.Component{ componentDidMount(){ 控制台日志(“安装”); } componentDidUpdate(){ 控制台日志(“更新”); } //const[SSVisibility,setSSVisibility]=useState(true); render(){ console.log(“渲染应用程序”); 返回( SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS {/* */} ); } } 导出默认应用程序;,reactjs,html-rendering,Reactjs,Html Rendering,使用这段简单的代码,我的render方法将被调用两次。我不明白为什么它是因为严格模式,下面的代码没有演示它,因为它将使用产品集true构建它(我认为) class.Component{ componentDidMount(){ console.log('mounting strict'); } componentDidUpdate(){ console.log(“更新”); } //const[SSVisibility,setSSVisibility]=useState(true); rend

使用这段简单的代码,我的render方法将被调用两次。我不明白为什么它是因为严格模式,下面的代码没有演示它,因为它将使用产品集true构建它(我认为)

class.Component{
componentDidMount(){
console.log('mounting strict');
}
componentDidUpdate(){
console.log(“更新”);
}
//const[SSVisibility,setSSVisibility]=useState(true);
render(){
log('rendering strict');
返回(
{/*    */}
);
}
}
类非严格扩展React.Component{
componentDidMount(){
console.log(“安装不严格”);
}
componentDidUpdate(){
console.log(“更新”);
}
//const[SSVisibility,setSSVisibility]=useState(true);
render(){
log(“呈现非严格”);
返回(
{/*    */}
);
}
}
常量应用=()=>{
返回(
);
};
ReactDOM.render(,document.getElementById('root'))


我猜这个应用程序被包装在一个“虽然它对我来说可能永远是模糊的,但我不能不意识到它的力量”——纳森·阿尔格伦上尉,我的意思是说,这是因为严格的模式,但为什么though@noob7React需要多次渲染到。在为生产构建时,严格模式不会执行此操作(这就是代码段不散布多个日志的原因)
import './App.css';
import SolarSystem from './components/solarSystem/solarSystem';

class  App extends React.Component {
  componentDidMount(){
    console.log("mounting");
  }

  componentDidUpdate(){
    console.log("updating");
  }
  //const [SSVisibility, setSSVisibility] = useState(true);
  render(){ 
    console.log("rendering app");
    return (
    <div className="App">ssssssssssssssssssssssssssssssss
    {/*   <SolarSystem isShowing={"yolo"} toggle={"polo"}></SolarSystem> */}
    </div>
  );
}
}
export default App;