react icon indicating copy to clipboard operation
react copied to clipboard

useCurrentStateAndParams don't reacting on initial state

Open verbart opened this issue 4 years ago • 3 comments

On refresh browser page, this hook return empty state, instead of my correct state: {"name":"","url":"^","views":null,"params":{"#":{"value":null,"type":"hash","dynamic":true}},"abstract":true}.

But router.transitionService.onSuccess called with my correct state.

export const useCurrentStateAndParams = () => {
  const globals = useRouter().globals;
  const [ stateData, setStateData ] = useState({ state: globals.current, params: globals.params });

  router.transitionService.onSuccess({}, (transition) => {
    // Reacting with my correct state
    console.log('onSuccess');
    setStateData({ state: transition.to(), params: transition.params('to') });
  });

  useOnStateChanged((state, params) => {
    // Reacting with empty state
    console.log('useOnStateChanged');
    setStateData({ state, params });
  });

  return stateData;
};

verbart avatar Jun 01 '21 16:06 verbart

I am picking up this

nikhilgupta58 avatar Jan 01 '22 14:01 nikhilgupta58

Is anyone here

darkknight20032001 avatar Jun 19 '22 22:06 darkknight20032001

Is anyone here

Better use react-router

verbart avatar Jun 19 '22 22:06 verbart

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues may be reopened.

Thank you for your contributions!

stale[bot] avatar Jan 07 '23 19:01 stale[bot]

This issue has been automatically closed.

stale[bot] avatar May 21 '23 19:05 stale[bot]