โ† Cognizant questions

Build a React Counter Component

Filed under Cognizant

Free read 2 of 3

The question

Implement a React component that displays a counter with buttons to increment, decrement, and reset the value.

Constraints

  • Use React hooks (useState)
  • State must update the UI correctly
  • Clear button should reset count to 0

Examples

Input
Click Increment twice, then Clear
Output
Count: 0
Why
Incrementing twice makes count 2, then Clear resets it to 0.

Approach

  1. Initialize a count variable using useState(0).

Tips

  • What they are testing: Tests understanding of component state and event handling.
  • Common mistake: Mutating state directly instead of using the setter function provided by useState.

Related Cognizant questions

Collected from public candidate posts and coding forums. Updated Nov 2026.