0
Hours
0
Minutes
0
Seconds

How to create usePrevious hook in React.js? | JavaScript Interview Question | Frontend Problem Solving
@Devtools Tech

336

React Hooks are a new addition in React 16.8. They let us use state and other React features without writing a class.

This also brings a question that when using hooks how go I get the previous value of props or state? We know that in class components, we have the option of componentDidUpdate method which receives previous props and state as arguments.

So, in this question, you need to create a custom hook usePrevious that provides us with the previous value.

Submission

Start the timer and try to complete the solution within 30 mins and share it on LinkedIn & Twitter and tag @devtoolstech @yomeshgupta

Our Solution