I built up a react-final-form that would render across multiple tabs. I have a Tabs component that tracks the active tab index and displays the appropriate 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>
);
When I create the TabPanels I specify a key using shortid.generate() so as to generate a unique value.
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>
));
The update depth exceeded error indicates the error happened in react-final-form's Field component:
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)
I'm really flummoxed by this... why would calling shortid.generate() result in this behaviour? I can swap it out with key={new Date().toString()} and the form renders fine.
CodeSandbox showing the issue: https://codesandbox.io/s/react-final-form-field-arrays-ksx15