Skip to content

Instantly share code, notes, and snippets.

@amite
Created January 22, 2019 05:53
Show Gist options
  • Save amite/03d58a56d5115ca191c2137b93034e08 to your computer and use it in GitHub Desktop.
Save amite/03d58a56d5115ca191c2137b93034e08 to your computer and use it in GitHub Desktop.
React Final form Fields component
import React from 'react'
import { Field } from 'react-final-form'
const Fields = ({
names,
subscription,
fieldsState = {},
children,
originalRender,
}) => {
if (!names.length) {
return (originalRender || children)(fieldsState)
}
const [name, ...rest] = names
return (
<Field name={name} subscription={subscription}>
{fieldState => (
<Fields
names={rest}
subscription={subscription}
originalRender={originalRender || children}
fieldsState={{ ...fieldsState, [name]: fieldState }}
/>
)}
</Field>
)
}
export default Fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment