TikTok Coding Interview / OA Question: React Counter App

18 Views
No Comments

Build a React app that displays a counter starting at 0.

Requirements:

  • Show the text You clicked {count} times.
  • Render a button labeled Click Me.
  • When the button is clicked, increase the counter by 1.
  • Use React state to store and update the count.
  • Include a navbar component with the title React App.

The component should use the provided h8k-navbar component. The counter text should have data-testid="output", and the button should have data-testid="add-button".

This is a classic React state-management exercise. The key idea is to store the counter value with useState and increment it on each button click using setCount(count + 1). The UI includes a navbar titled "React App", a text output showing "You clicked {count} times", and a "Click Me" button with the required test IDs. It is a straightforward but important frontend OA question focused on component state and event handling.

END
 0