Type Safety Problem While Using TypeScript with React
Learn about the type safety problem of TypeScript and some solutions to it.
We'll cover the following...
The fundamental problem
The core issue on our side is not necessarily a TypeScript problem. It’s a React problem:
When we call
React.createContext
, TypeScript will want to know what value we can expect.But we don’t have that value yet because we have to wait for the
Provider
component to mount to useuseState
.TypeScript will consider this an issue because we’re passing it something that isn’t what it expects. ...