const CounterContext = createContext();
export function CounterProvider(props) {
const [count, setCount] = createSignal(0),
store = [
count
];
return (
<CounterContext.Provider value={store}>
{props.children}
</CounterContext.Provider>
);
}
export function useCounter() { return useContext(CounterContext); }
I want to use this useCounter
outside of the provider, after an external event like a setTimeout
or an incoming Websocket message.
setTimeout(() => {
const [count] = useCounter();
createEffect(on(count, () => {
console.log(count)
}))
})
This seems like a bad idea, but I have this in my application code, and I don't know how to restructure my code to avoid this.