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 am looking to utilize the useCounter
function outside of the provider context, triggered by an external event such as a setTimeout
or data received via WebSocket.
setTimeout(() => {
const [count] = useCounter();
createEffect(on(count, () => {
console.log(count)
}))
})
Although I realize this approach may not be ideal, it is currently implemented in my application code. However, I am open to suggestions on how to refactor my code to eliminate this.