Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useCurrentStateAndParams don't reacting on initial state #914

Closed
verbart opened this issue Jun 1, 2021 · 5 comments
Closed

useCurrentStateAndParams don't reacting on initial state #914

verbart opened this issue Jun 1, 2021 · 5 comments
Labels

Comments

@verbart
Copy link

verbart commented Jun 1, 2021

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;
};
@nikhilgupta58
Copy link

I am picking up this

@darkknight20032001
Copy link

Is anyone here

@verbart
Copy link
Author

verbart commented Jun 19, 2022

Is anyone here

Better use react-router

@stale
Copy link

stale bot commented Jan 7, 2023

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 stale bot added the stale label Jan 7, 2023
@stale
Copy link

stale bot commented May 21, 2023

This issue has been automatically closed.

@stale stale bot closed this as completed May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants