Created
January 22, 2019 05:53
-
-
Save amite/03d58a56d5115ca191c2137b93034e08 to your computer and use it in GitHub Desktop.
React Final form Fields component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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