this is my component:
import { Field, FieldArray, Form, Formik } from "formik";
import { connect } from "react-redux";
import { withRouter } from "react-router";
import { updateEpisode } from "../../ducks/episodes/actions";
const AddActorToMovie = (
{ history, updateEpisode, episode, characters },
props
) => {
const handleSubmit = (values) => {
updateEpisode(values);
history.push("/episodes");
};
console.log("halo", episode);
return (
<div>
{episode ? (
<div>
<h3>Add Main Character to episode</h3>
<Formik
initialValues={{
id: episode.id,
title: episode.title,
release_date: episode.release_date,
series: episode.series,
img: episode.img,
charactersList: episode.charactersList, // this would be an array
}}
onSubmit={(values) => handleSubmit(values)}
enableReinitialize={true}
>
<Form>
<Field name="charactersList" as="select">
<option value=""> Brak informacji </option>
{characters.map((char) => (
<option
key={char.id}
value={char.id}
>{`${char.name}`}</option>
))}
</Field>
<button type="submit">Zatwierdz</button>
</Form>
</Formik>
</div>
) : (
<div>Loading...</div>
)}
</div>
);
};
const mapStateToProps = (state, props) => {
return {
episode: state.episodes.episodes
? state.episodes.episodes.find(
(x) => String(x.id) === props.match.params.id
)
: null,
characters: state.characters.characters,
};
};
const mapDispatchToProps = {
updateEpisode,
};
export default withRouter(
connect(mapStateToProps, mapDispatchToProps)(AddActorToMovie)
);
What i would like to do, is instead of adding only one value = char.id to charactersList i woudl like to add multiple. So that charactersList woudl be an array and i could add as many characters i could and also if possible i could also delete some of them in this form, as im using my updateEpisode action so that im passing a updated object to my state.
I know that probably i shoudl do it with FieldArray but i don't know how.