Skip to content
Advertisement

How to change the child state component from parent in functional component

I have created a Count down timer component and I have a Button near this component

and I want when users click on this button, resets the timer

and for doing this I should change the child state

I found the solution for changing parent state from the child but I don’t find the solution to this

can it be solved with ref ?? ( my timer component is a functional component )

Advertisement

Answer

React ref forwarding is the solution: This blog will describe more: https://medium.com/javascript-in-plain-english/react-refs-both-class-and-functional-components-76b7bce487b8

JavaScript

I have added both ref forwarding with class components and functional components. It is same with both React.js and React native.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement