Skip to content

Reset the param on route change #27

Discussion options

You must be logged in to vote

Hi @batuhanbuena .

Normally can reset all params like setUrl(form) where form is the defaultState.

Just curious, why need to reset state before page change?

About page change, can try to use useEffect , e.g return unsubscribe function from it, like

const { urlState, setUrl, reset } = useUrlState(eventState);

React.useEffect(() => {
  ...
  return () => {
    reset()
    // same as setUrl(eventState);
  }
  // eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

Can wrap hook into another hook if there is some specific logic, something like

const useEventState = (reset = false) => {
 const result = useUrlState(eventState)

  React.useEffect(() => {
    return () => {
      if (reset) 

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by asmyshlyaev177
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@asmyshlyaev177
Comment options

Comment options

You must be logged in to vote
1 reply
@asmyshlyaev177
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
FAQ General questions about functionality and usage.
2 participants