Skip to content
Snippets Groups Projects
Commit 1714fa38 authored by Santiago Rafael Gonzalez Pereyra's avatar Santiago Rafael Gonzalez Pereyra
Browse files

Layout component fix

parent d7d862d7
No related branches found
No related tags found
No related merge requests found
import { Reducer, useCallback, useMemo, useReducer, useRef } from "react"; import React, { Reducer, useCallback, useMemo, useReducer, useRef } from "react";
import { HeaderProps } from "../components/header/Header"; import { HeaderProps } from "../components/header/Header";
import React from "react";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { styles } from "./Layout.styles"; import { styles } from "./Layout.styles";
...@@ -70,23 +69,22 @@ export const Layout: React.FunctionComponent<LayoutProps> = observer(props => { ...@@ -70,23 +69,22 @@ export const Layout: React.FunctionComponent<LayoutProps> = observer(props => {
if (props.layoutOptions) optionsSource.push(props.layoutOptions); if (props.layoutOptions) optionsSource.push(props.layoutOptions);
if (routeKeyRef.current === props.routeKey) optionsSource.push(options); if (routeKeyRef.current === props.routeKey) optionsSource.push(options);
else routeKeyRef.current = props.routeKey; else {
dispatchOptions({ type: "reset" });
routeKeyRef.current = props.routeKey;
}
return mergeLayoutOptions(...optionsSource); return mergeLayoutOptions(...optionsSource);
}, [options, props.layoutOptions, props.routeKey]); }, [options, props.layoutOptions, props.routeKey]);
const mergedOptionsRef = useRef<RecursivePartial<LayoutOptions>>(mergedOptions); const mergedOptionsRef = useRef<RecursivePartial<LayoutOptions>>(mergedOptions);
React.useEffect(() => { mergedOptionsRef.current = mergedOptions;
mergedOptionsRef.current = mergedOptions;
}, []);
const setLayoutOptions = useCallback<SetLayoutOptions>( const setLayoutOptions = useCallback<SetLayoutOptions>(newOptions => {
newOptions => dispatchOptions({
dispatchOptions({ type: "update",
type: "update", newOptions: typeof newOptions === "function" ? newOptions(mergedOptionsRef.current) : newOptions,
newOptions: typeof newOptions === "function" ? newOptions(mergedOptionsRef.current) : newOptions, });
}), }, []);
[]
);
return ( return (
<LayoutContext.Provider value={setLayoutOptions}> <LayoutContext.Provider value={setLayoutOptions}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment