I have two components which are located in different position in the hierarchy. One component has data which should be used in another component. I was trying to achieve this with custom hook. When I used in components I'm getting false, I want it to be true because I set it to true from component 1 so component 2 should get true. I don't know little bit confused on custom hooks.
Custom Hook
export const useShareData = () => {
const [data, setData] = useState<boolean>(false)
const setValue = (value: boolean) => {
setData(value)
}
return [data, setValue]
}
Component 1
const [data, setData] = useShareData()
const dataToBeShared = true
useEffect(()=>{
setData(dataToBeShared)
},[dataToBeShared])
Component 2
const [data] = useShareData()
console.log(data)
In component 2 the value is always false.