I would like to use axios to fetch the values from API in react.js, and set it as a form, but it doesn't display any fetched data at all.
export default function Review() {
const [fetchedData, setFetchedData] = useState([]);
const [fetchedlanguage, setlanguage] = useState([]);
useEffect(() => {
const getStudent = async () => {
const stu = await axios.get('http://localhost:8000/students/');
setFetchedData(stu.data.students[0]);
setlanguage(stu.data.students[0].languages)
};
getStudent()
},[]);
console.log("student: ", fetchedData);
const [formdata, setformdata] = useState({
availability: 6,
preference:'201, 301',
experience:'201',
language:fetchedlanguage[0],
background:fetchedData.background,
});
Even though the console.log shows the data correctly, when I set the form here, how come there is no updates on data?