How to keep React component state between mount/unmount?

后端 未结 8 1656
心在旅途
心在旅途 2020-12-12 18:15

I have a simple component that maintains an internal state. I have another component that toggles whether or not <

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 18:36

    If you want to be able to unmount and mount while maintaining state, you will need to store the count in App and pass down the count via props.

    (When doing this, you should be calling a toggle function inside of App, you want the functionality which changes data to live with the data).

    I will modify your fiddle to be functional and update my answer with it.

提交回复
热议问题