Skip to content

Commit

Permalink
fix: Only run initialization effect on first render
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Feb 23, 2020
1 parent 834c755 commit 7788a98
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/UIRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ export const InstanceOrPluginsMissingError = `Router instance or plugins missing
*/
export function UIRouter(props: UIRouterProps) {
const uiRouter = useRef<UIRouterReact>();
const [_hasStarted, start] = useState<boolean>(false);
const [started, setStarted] = useState<boolean>(false);

useEffect(() => {
// Router hasn't been initialised yet, this is the first render
if (!uiRouter.current) {
// Router hasn't been initialised yet, this is the first render
const { config, states, plugins, router } = props;
if (router) {
uiRouter.current = router;
Expand All @@ -144,9 +144,9 @@ export function UIRouter(props: UIRouterProps) {
}

uiRouter.current.start();
start(true);
setStarted(true);
}
});
}, []);

return uiRouter.current ? (
<UIRouterContext.Provider value={uiRouter.current}>{props.children}</UIRouterContext.Provider>
Expand Down

0 comments on commit 7788a98

Please sign in to comment.