← All React exercises

React quiz · 11

What does the code snippet to the right output by console.log?

StatusNot taken

Question

What does the code snippet to the right output by console.log?

Code

exercise.tsx
1// This is a React Quiz from BFE.dev
2
3import * as React from 'react'
4import { memo, useState} from 'react'
5import { createRoot } from 'react-dom/client'
6import { screen, fireEvent } from '@testing-library/dom'
7
8function _A({ onClick }) {
9  console.log('A')
10  return <button onClick={onClick} data-testid="button">click me</button>
11}
12
13const A = memo(_A)
14
15function App() {
16  console.log('App')
17  const [state, setState] = useState(0)
18  return <div>
19    {state}
20    <A onClick={() => {setState(state => state + 1)}}/>
21  </div>
22}
23
24const root = createRoot(document.getElementById('root'));
25root.render(<App/>);
26
27// click the button
28;(async function() {
29  const button = await screen.findByTestId('button')
30  fireEvent.click(button)
31})()