React 组件状态管理 useContext 的 Provider 怎么传递额外参数?-灵析社区

MaxClick

用initialData属性来初始化useState: export function FormProvider({ children, initialData } : { children: React.ReactNode, initialData: any }) { const [form, setForm] = useState(initialData || {}); return ( {children} ); } 用的时候: // ... 组件

阅读量:1

点赞量:0

问AI