Difficile
Que va afficher ce composant ?
const MyComponent = () => {
const [index, setIndex] = useState(1);
setIndex(2);
return <div>{index}</div>;
}
Auteur: Vincent CotroStatut : PubliéeQuestion passée 3021 fois
Modifier
4
Évaluations de la communauté
Auteur anonyme
13/11/2023
Because updating your state will create a new render. You should only update your state conditionnaly (for exemple using a "onClick" or a condition)
The loop will look like this :
- Rendering
- Updating state (with setIndex(2))
- Rendering
- Updating state (with setIndex(2))
etc...
Questions similairesPlus de questions sur React