I have put my data response in a useState. Then i am trying to get the input data using map function like i used to. Whats probably the issue that it didnt work? Did i map it incorrectly?
const WatchList = () => {
const [data, setData] = useState();
const formik = useFormik({
initialValues: {
name: "",
description: "",
},
onSubmit: (values) => {
if (localStorage.getItem("sessionID")) {
const createList = async () => {
axios({
method: "post",
url: `https://api.themoviedb.org/3/list?api_key=${API_KEY}&session_id=${localStorage.getItem(
"sessionID"
)}`,
data: {
name: values.name,
description: values.description,
},
})
.then((response) => {
const list_id = response.data.list_id;
axios({
method: "get",
url: `https://api.themoviedb.org/3/list/${list_id}?api_key=${API_KEY}&language=en-US`,
})
.then((response) => {
setData(response.data);
})
.catch((error) => {
console.error(error);
});
})
.catch((error) => {
console.error(error);
});
};
createList();
}
},
});
return (
<>
<div className="container-md my-3 text-white">
<div className="text-center">
<h2>Create a list</h2>
</div>
<div className="row justify-content-center">
<div className="col-md-6">
<form onSubmit={formik.handleSubmit}>
<div className="mb-3">
<label htmlFor="name">Name</label>
<input
id="name"
name="name"
type="text"
onChange={formik.handleChange}
onBlur={formik.handleBlur}
value={formik.values.name}
className="form-control"
/>
{formik.touched.name && formik.errors.name ? (
<div>{formik.errors.name}</div>
) : null}
</div>
<div className="mb-3">
<label htmlFor="description">Description</label>
<textarea
id="description"
name="description"
type="text"
onChange={formik.handleChange}
onBlur={formik.handleBlur}
value={formik.values.description}
className="form-control"
cols="30"
rows="7"
/>
{formik.touched.description && formik.errors.description ? (
<div>{formik.errors.description}</div>
) : null}
</div>
<div className="text-center">
<button type="submit" className="btn button-style text-white">
Create
</button>
</div>
</form>
</div>
</div>
</div>
<div className="container-md">
{data &&
data.results.map((item) => (
<>
<div key={item.id}>
<h1>{item.name}</h1>
</div>
</>
))}
</div>
</>
)
}