() But actually it will not work, because Expected 1 argum" /> () But actually it will not work, because Expected 1 argum" /> () But actually it will not work, because Expected 1 argum"/>

Why basic example in mobx with react createContext don't have default value?

19 views Asked by At

Here inside "using React context" tab you can see:

const TimerContext = createContext<Timer>()

But actually it will not work, because

Expected 1 arguments, but got 0.ts(2554)

index.d.ts(419, 9): An argument for 'defaultValue' was not provided.

If I do something like this:

const TimerContext = createContext<Timer | null>(null);

then I should check for null in places where I use context (for example useContext()?.someValue), which is also looks not good.

So what it is the right approach?

0

There are 0 answers