import * as React from "react"; import { useState } from "react"; interface AppState { username: string; shoppingCart: { items: { id: number; name: string }[] }; } const defaultContextValue: AppState = { username: "徐嘉其", shoppingCart: { items: [] }, }; export const appSetStateContext = React.createContext< React.Dispatch> | undefined >(undefined); export const appContext = React.createContext(defaultContextValue); export const AppStateProvider: React.FC = (props) => { const [state, setState] = useState(defaultContextValue); return ( {props.children} ); };