Easy
What will this component display?
const MyComponent=()=>{
const[index, setIndex]= useState(1);
useEffect(()=>{
setIndex(2);
},[]);
return<div>{index}</div>;
};
Author: Vincent CotroStatus: PublishedQuestion passed 3232 times
Edit
7
Community Evaluations
Ambiguous
Auteur anonyme15/08/2024
The component will display 1 initially, and then call useEffect which will update the state and then 2 is displayed, so I think the question is ambiguous, it should ask what will it show last?
Similar QuestionsMore questions about React