動くコード図鑑技術記事現場の渡り方キャリア論すべての記事About
TypeScript

createContextでContextとProviderを作る

出典: React×TypescriptでuseContext使ってReduxライクなState管理をしてみるcreateContextでContextとProviderを作る

createContextでContextとProviderを作る (typescript)#bcf866e4af9f
type CounterContextState = {
    count : number,
    dispatch : React.Dispatch<CounterActions>
}
 
export const CounterContext = createContext<CounterContextState>({} as CounterContextState);
▸ この snippet は実行結果未収録
▸ 実行結果は未収録です
  • id: #bcf866e4af9f
  • lines: 6
  • extracted: 2026-06-10

Source収録記事

この snippet は記事の「createContextでContextとProviderを作る」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。

同じ記事から

4
図鑑トップ