0
Follow
0
View

Incrementing state in a parent from a child component in react

Tanyo2012 注册会员
2023-01-24 22:45

Firstly thank you @GalAbra

I fixed this by updating the setCount() to use a callback function. React's useState's setter will populate with the current value

const increment = () => {setCount(c => c +1)}
sdjndy 注册会员
2023-01-24 22:45

Rather than using count and incrementing it every time doesn't seems to be optimized solution for this use case try this replace it with count

{children.filter(item => item.answered).length}

About the Author

Question Info

Publish Time
2023-01-24 22:45
Update Time
2023-01-24 22:45

Related Question