DEV Community

Discussion on: prevState with useReducer hook in React.

Collapse
 
lyrod profile image
Lyrod

I am puzzled by the usePrevious hook, a new instance is created for each render

Collapse
 
ivan_jrmc profile image
Ivan Jeremic • Edited

Thanks, Any recommendations?

Collapse
 
lyrod profile image
Lyrod

I think, creating the function outside of the component (for example: in a folder "hooks") is better.

Thread Thread
 
ivan_jrmc profile image
Ivan Jeremic

Yea I wanted somehow to include the code for the hook here so people can see it, but maybe I should have put it outside the Provider which would be the same effect as in a separate folder. Thanks