Question du test React ⚛️

UseState et useEffect en React

Très facile

Que va afficher ce composant ?

const MyComponent = () => {
    const [index, setIndex] = useState(1);

    useEffect(() => {
        setIndex(2);
    }, []);

    return <div>{index}</div>;
};
Auteur: Vincent CotroStatut : PubliéeQuestion passée 3283 fois
Modifier
7
Évaluations de la communauté
developer avatar
Ambiguë
Auteur anonyme
15/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?
developer avatar
Auteur anonyme
26/08/2024
I think it's not ambiguous to most people. It's classified as very easy because of this.