这有效:
在主视图中:
const methods = useForm(form)
const [value, setValue] = useState(0)
<FormProvider {...{value, ...methods}}>
</FormProvider>
示例选项卡项:
// first item
const TabItem1 = () => {
const {value} = useFormContext()
return <TabPanel {...{value, index: 0}}>
{/*{Content here}*/}
</TabPanel>
}
export default TabItem1
// second item
const TabItem2 = () => {
const {value} = useFormContext()
return <TabPanel {...{value, index: 1}}>
{/*{content here}*/}
</TabPanel>
}
export default TabItem2
和 TabPanel:
const TabPanel = ({children, value, index}) =>
<div style={{display: value === index ? 'block' : 'none'}}>
{children}
</div>
export default TabPanel