Question
What does the code snippet to the right output by console.log?
React quiz · 19
Question
Code
1// This is a React Quiz from BFE.dev
2
3import * as React from 'react'
4import { useState, useEffect } from 'react'
5import { createRoot } from 'react-dom/client'
6
7function App() {
8 const [state1, setState1] = useState(1);
9
10 const [state2] = useState(() => {
11 console.log(2);
12 return 2;
13 });
14
15 console.log(state1);
16
17 useEffect(() => {
18 setState1(3);
19 }, []);
20
21 return null;
22}
23
24const root = createRoot(document.getElementById("root"));
25root.render(<App />);