2016-12-25 56 views

回答

2

不要直接設置DOM。你需要閱讀setStateprops

setState會觸發重新渲染,因此無論您何時執行this.setState({minHeight: newValueHere});它都會自動使用新值更新渲染方法。

class Component extends React.Component { 
    constructor() { 
     super(); 

     this.state = { 
      minHeight: "600px" 
     }; 
    } 
    render() { 
     return (
     <div> 
      <div className="firstClass" style={{minHeight: this.state.minHeight}} /> 
      <div className="secondClass" style={{minHeight: this.state.minHeight}} /> 
     </div> 
     ); 
    } 
}