I wonder how come the code below works (it displays correct options in a dropdown), even though a warning in IntelliJ says 'Promise returned from Promise is ignored' and suggests changes to the code. Initial version of code:
import React, { useState, useEffect } from "react";
import axios from "axios";
const Cake = () => {
const [ing, setIng] = useState([]);
const [error, setError] = useState("");
const getIngredients = async () => {
// returns an array of strings
const url = new URL("someUrl");
const result = await axios.get(url.toString());
return result.data;
};
useEffect(() => {
new Promise((resolve, reject) => {
getIngredients()
.then((response) => setIng(response))
.then((response) => resolve(response))
.catch((error) => setError(error));
});
}, []);
return (
<div>
<Select options={ing} />
</div>
);
};
export default Cake;
IntelliJ suggests adding "then" to my Promise, like this:
useEffect(() => {
new Promise((resolve, reject) => {
getIngredients()
.then((response) => setIng(response))
.then((response) => resolve(response))
.catch((error) => setError(error));
}).then((r) => console.log(r));
}, []);