Typing createContext in React #typescript #react

preview_player
Показать описание
Become a TypeScript Wizard with my free beginners TypeScript Course:

Follow Matt on Twitter

Join the Discord:

Рекомендации по теме
Комментарии
Автор

Did this with tRPC when using protected routes. Guards are decent

StephenRayner
Автор

Is there something left in this example? Where will the user be set?
In my eyes the context is not really complete - the user state is missing.

HerrThomasE
Автор

How do we create generic type for creating context?

emreq
Автор

The real problem arises when the generic type of the context accepts a generic also…
So in this example User<TSomething>

Dani
Автор

Any suggestions/ resources for typing a generic function that accepts a reducer, an object of dispatch functions and the initial state and exports the Context and Provider? Trying abstract away some logic from my JS but confused by the typing.

cfesq
Автор

When is it a good idea to use React Contexts over Jotai, Zustand, Signals, or plain State?

Lexaire
Автор

I have an errorObject<T> that just errors when you access it in any way (as a proxy), and all the global stuff gets an error as a default, then use the context as normal.

Fsi
Автор

Teach us module augmentation. I faced this when using next auth package for Authentication. So if you use next auth pkg you gotta return a object of type User from authorize function.
To change the return type of the User object you gotta use augmentation. I hate this.teach me

jellyfish