You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{createContext}from"react";interfaceAppContextInterface{name: string;author: string;url: string;}constAppCtx=createContext<AppContextInterface|null>(null);// Provider in your appconstsampleAppContext: AppContextInterface={name: "Using React Context in a Typescript App",author: "thehappybug",url: "http://www.example.com",};exportconstApp=()=>(<AppCtx.Providervalue={sampleAppContext}>...</AppCtx.Provider>);// Consume in your appimport{ useContext }from"react";exportconstPostInfo=()=>{constappContext=useContext(AppCtx);return(<div>Name: {appContext.name},Author: {appContext.author},Url:{" "}{appContext.url}</div>
);};
Issue location
// appContext is possibly null?!<div>Name: {appContext.name}, Author: {appContext.author}, Url:{" "}{appContext.url}</div>
Site
react typescript cheatsheet
Section
Basic
Page
Context
Snippet
Issue location
Reproduce
Try Typescript Playground
Recommended PR
Add non-nullish assertion symbol
!
after appContext.The text was updated successfully, but these errors were encountered: