DEV Community

loading...

Discussion on: How to convert a React Class Component to a Function Component

Collapse
email2vimalraj profile image
Vimalraj Selvam

Thanks for sharing this Seb, this will be really useful. One question though, how do we translate the componentWillReceiveProps?

Collapse
sebtoombs profile image
Seb Author

Hey Vimalraj! This one's a tricky one. Essentially it will depend on your use case, and you should probably be able to find a way to achieve a similar thing using simpler hooks. componentWillReceiveProps has been deprecated for a couple of reasons but my understanding is it was generally misused.

My general advice would be; replace it with a useEffect hook, and then use a custom hook to check the previous state. I haven't written about a hook to use previous values, but the logrocket blog has a great example.

I'll update the post to include this! Thank you