I am working on a favicon component, which will go into the <HEAD>
within DOM.
I want to set a recoil state so that based on user actions, I can update the favicon & show updates to the user on the browser tab.
The favicon component is simply like this for now:
const Favicon: FC = () => {
const favNotice = useRecoilValue(faviconSt);
return (
<link rel="icon" href={favNotice ? "favicon_heart.svg" : "favicon.svg"} />
);
};
I am getting the error:
TypeError: Cannot read properties of null
I am not clear why this is the case. Here is my main component, which shows that the recoil root state is initialised before the page component is rendered. The page component is wrapped within a <Layout>
component & it is the Layout component, within which, I render the Favicon component.
export default function App({ Component, pageProps }: AppProps) {
const getLayout = Component.getLayout || (page => page);
return (
<ErrorBoundary
FallbackComponent={RootErrorFallback}
onReset={useQueryErrorResetBoundary().reset}>
<RecoilRoot>
<div className="__APP__">
<div className="pageContainer">
<Suspense fallback={<Loader />}>
{getLayout(<Component {...pageProps} />)}
</Suspense>
</div>
<Overlay />
</div>
</RecoilRoot>
</ErrorBoundary>
);
}
I dont understand why the recoil state is not read within the component when the recoil-root has already been intialised?