useReduxContext.js:24 Uncaught Error: could not find react-redux context value; please ensure the component is wrapped in a
I have a simple custom hook and I am trying to call redux dispatch from my hook in order to organize my logic in 1 place instead call the dispatch in each component
my custom hook:
export function useToggle(data:any) {
const [val, setToggle] = React.useState(data:any);
const dispatch = useDispatch();
const onToggle = (event: any, val: any) => {
setToggle(val)
};
useEffect(()=>{
setToggle(data:any)
},[data:any])
return { val, onToggle };
}
my component that calls the hook for sure is under provider
this my componenet :
<Parent
>
<Child />
<Child2>{renderData()}</Child2>
</Parent>
and inside Child 2 I have a simple function component with this code
const { val, onToggle } = useToggle(data);
my index.ts
ReactDOM.render(
<Provider store={store}>
<App history={history} />
</Provider>,
document.querySelector('#root')
);