Last active
September 28, 2020 08:02
-
-
Save YounglanHong/1e9a12e9acf64035ebf4c7a666186fb1 to your computer and use it in GitHub Desktop.
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
//* Formik props | |
const initialValues = { | |
decks: [""], // --- 1️⃣ | |
}; | |
const onSubmit = (values, actions) => { | |
registerDeck(values.decks); | |
getDeck(); | |
// 입력창 초기화 | |
actions.resetForm({ | |
values: { | |
decks: [""], | |
}, | |
}); | |
}; | |
<Formik initialValues={initialValues} onSubmit={onSubmit}> | |
<Form> | |
<FieldArray name="decks"> | |
{(fieldArrayProps) => { | |
const { push, remove, form } = fieldArrayProps; | |
const { decks } = form.values; | |
return ( | |
<div> | |
{decks && | |
decks.map((deck, index) => ( | |
<Field | |
name={`decks[${index}]`} {/* --- 2️⃣ */} | |
placeholder="deck name" | |
/> | |
<AddIcon onClick={() => push("")} /> | |
<RemoveIcon onClick={() => remove(index)} /> | |
))} | |
</div> | |
); | |
}} | |
</FieldArray> | |
</Form> | |
</Formik> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment