Skip to content

Instantly share code, notes, and snippets.

@crrmacarse
Created January 28, 2020 07:26
Show Gist options
  • Save crrmacarse/a66e2fe3b2f5a7d859840d271947d5d2 to your computer and use it in GitHub Desktop.
Save crrmacarse/a66e2fe3b2f5a7d859840d271947d5d2 to your computer and use it in GitHub Desktop.
Toggling of components without changing of route. The awesome stuff? selected state persist still even on route change!
// Implemented here: https://crrmacarse.github.io/personal
// NOTE:
// It could probably lead to a bug when you try to add multiple of these across components
// link routes that'll will assure of state existence
<Link to={(location) => ({ ...location, pathname: 'go' })}>Go</Link>
<Link to={(location) => ({ ...location, pathname: 'current' })}>Current</Link>
// to pass a state value to the current path
<Link
to={{
state: "store state",
}}
>
Selecting the same route
</Link>
// handle changes via here
const { state } = useLocation();
useEffect(() => {
if (state) {
// change local state of desired
}
}, [state]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment