Updating state on props change in React Form

前端 未结 11 1971
时光说笑
时光说笑 2020-12-02 04:15

I am having trouble with a React form and managing the state properly. I have a time input field in a form (in a modal). The initial value is set as a state variable in

11条回答
  •  我在风中等你
    2020-12-02 05:18

    There is also componentDidUpdate available.

    Function signatur:

    componentDidUpdate(prevProps, prevState, snapshot)
    

    Use this as an opportunity to operate on the DOM when the component has been updated. Doesn't get called on initial render.

    See You Probably Don't Need Derived State Article, which describes Anti-Pattern for both componentDidUpdate and getDerivedStateFromProps. I found it very useful.

提交回复
热议问题