Splitting ContextProvider definition from context value using part
tolgaduzenli opened this issue · comments
Is there a way to split the ContextProvider definition from useContex?
Here is example, I tried to split but doesn't work.
Codesandbox
It's not possible. You would have to create a separate file and export both:
import constate from "constate";
import useCounter from "./counterContext";
export const [CounterProvider, useCounterContext] = constate(useCounter);
@diegohaz Thanks for the quick response.
I am using previous version (not 2.0.0), TBH, it was easier than now. I dont why you converted this way. Most probably you have reason(s) to have like this.
Maybe I misunderstood and couldnt figure out how can I import just one ContextProvider above everything, and access context from children components. Exactly like we were using with previous version.
I don't remember this being possible in v1. How were you doing it?
yes here it is; codesandbox
please check version of constate
Ah, I thought you were talking about a different thing.
Anyway, it's super easy to get the same API:
const [CounterProvider, useCounterContext] = constate(useCounter);
useCounterContext.Provider = CounterProvider;
export { useCounterContext };
Thanks @diegohaz I knew I misunderstood the concept. Updated same codesandbox with new version and your suggestion. If someone needs, just check same codesandbox from previous psts.