Is it possible to share states between components using the useState() hook in React?

后端 未结 7 1338
春和景丽
春和景丽 2020-12-13 00:19

I was experimenting with the new Hook feature in React. Considering I have the following two components (using React Hooks) -

const HookComponent = () =>         


        
相关标签:
7条回答
  • 2020-12-13 00:53

    You will still need to lift your state up to an ancestor component of HookComponent1 and HookComponent2. That's how you share state before and the latest hook api doesnt change anything about it.

    0 讨论(0)
提交回复
热议问题