setState() inside of componentDidUpdate()

后端 未结 6 2043
鱼传尺愫
鱼传尺愫 2020-11-28 03:23

I\'m writing a script which moves dropdown below or above input depending on height of dropdown and position of the input on the screen. Also I want to set modifier to dropd

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 03:57

    I would say that you need to check if the state already has the same value you are trying to set. If it's the same, there is no point to set state again for the same value.

    Make sure to set your state like this:

    let top = newValue /*true or false*/
    if(top !== this.state.top){
        this.setState({top});
    }
    

提交回复
热议问题