我构建了一个 react-final-form 可以跨多个选项卡呈现。我有一个Tabs
组件可以跟踪活动选项卡索引并显示适当的TabPanel
.
const App = () => (
<Styles>
<Form
onSubmit={_ => _}
mutators={{
...arrayMutators
}}
>
{({ handleSubmit, submitting, values, form: { mutators } }) => {
const tabs = [
{
tabName: "General",
tabPanel: <div>I am the general pane</div>
},
{
tabName: "Activity",
tabPanel: <Activity mutators={mutators} />
},
{
tabName: "Delay reasons",
tabPanel: <div>I am the delay reasons panel</div>
}
];
return (
<form onSubmit={handleSubmit}>
<Tabs values={tabs} />
</form>
);
}}
</Form>
</Styles>
);
当我创建TabPanel
s 时,我指定一个键shortid.generate()
来生成唯一值。
const tabPanels = props.values.map((value, index) => (
// Note that if key is set with shortid, a setState infinite loop
// error will be thrown
<TabPanel
index={index}
key={shortid.generate()}
activeTabIndex={activeTabIndex}
>
{value.tabPanel}
</TabPanel>
));
更新深度超出错误表示错误发生在react-final-form
'sField
组件中:
The above error occurred in the <Field> component:
in Field (at ActivityPanel.tsx:39)
in div (at ActivityPanel.tsx:37)
in div (created by styled.div)
in styled.div (at ActivityPanel.tsx:28)
我真的对此感到困惑......为什么打电话会shortid.generate()
导致这种行为?我可以把它换掉,key={new Date().toString()}
表格渲染得很好。
显示问题的 CodeSandbox:https ://codesandbox.io/s/react-final-form-field-arrays-ksx15