I am setting a localstorage value when the user clicks onto a page in the app training.js
and then I want this value to be read by sidebar.js
, when the localstorage items is set it only outputs the value in the console.log
once the user opens or closes the sidebar, it is not being picked up when the props changes as I would expect by useEffect.
How can I get useEffect to pick up the value when it changes?
training.js
{typeof window !== 'undefined' && localStorage.setItem(topic.slug, topic.progress)}
sidebar.js
const Sidebar = () => {
const structureAndDetails = typeof window !== 'undefined' ? Number(localStorage.getItem('structure-and-details')) : null
const hydraulics = typeof window !== 'undefined' ? Number(localStorage.getItem('hydraulics')) : null
useEffect(() => {
console.log('hydraulics',hydraulics)
}, [hydraulics])