Figured I’d share one of the first use cases I found for this and it’s one I believe could be helpful to others. That’s in hydrating state with React Router useHistory state in the event of a browser refresh.
import React from ‘react’ const CheckIfCacheNeeded = ({ value, setValue, fallbackValue, handleRestore, children }) => { value != undefined ? value : handleRestore(fallbackValue, setValue) return( {children} ) } export default CheckIfCacheNeeded
When calling the component you’d need to add a handleRestore function that took the fallbackValue and setter function as parameters.
It works well with React Router useHistory state that persists during browser refresh.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Figured I’d share one of the first use cases I found for this and it’s one I believe could be helpful to others. That’s in hydrating state with React Router useHistory state in the event of a browser refresh.
When calling the component you’d need to add a handleRestore function that took the fallbackValue and setter function as parameters.
It works well with React Router useHistory state that persists during browser refresh.