Back

Like Dislike I

easy

Streak

0 days

Progress

0%

Submitted

0

Like Dislike I

React20 mineasyFree

Prompt

Build this React exercise in 20 minutes.

Build a local reaction pair with baseline counts of 128 likes and 4 dislikes. The baseline excludes this visitor. A visitor has exactly one of three states: neutral, like, dislike. Clicking the active reaction clears it; switching moves the visitor’s one vote. No persistence, API, loading state, or optimistic write is required.

Acceptance checks

  • Neutral → like → dislike → neutral gives counts 128/4 → 129/4 → 128/5 → 128/4.
  • Repeated toggles and switching never drift from baseline plus the current reaction.
  • Queued toggles compute from the latest state; only one button can be pressed.
  • Buttons expose selected text and aria-pressed, and can be activated by Enter/Space.

The checks are a manual interview checklist; saving a submission does not execute them.

Learn and continue

Prerequisite: Functional state updates. Work through the React Machine Coding Foundations path to practice related skills in order.

Requirements

  • →Neutral → like → dislike → neutral gives counts 128/4 → 129/4 → 128/5 → 128/4.
  • →Repeated toggles and switching never drift from baseline plus the current reaction.
  • →Queued toggles compute from the latest state; only one button can be pressed.
  • →Buttons expose selected text and aria-pressed, and can be activated by Enter/Space.

Starter packet

What the interviewer handed you

Build a local reaction pair with baseline counts of 128 likes and 4 dislikes. The baseline excludes this visitor. A visitor has exactly one of three states: neutral, like, dislike. Clicking the active reaction clears it; switching moves the visitor’s one vote. No persistence, API, loading state, or optimistic write is required.

Manual acceptance checks

  • Neutral → like → dislike → neutral gives counts 128/4 → 129/4 → 128/5 → 128/4.
  • Repeated toggles and switching never drift from baseline plus the current reaction.
  • Queued toggles compute from the latest state; only one button can be pressed.
  • Buttons expose selected text and aria-pressed, and can be activated by Enter/Space.

Likely follow-ups

  • • What changes when two devices vote as the same user?
Example
Loading preview...
For the best coding experience, we recommend using a desktop device.
Preparing Sandbox...
Premium interview report

What interviewers score in this build

Use this before reading the code. It tells you what to say, what to test, and where machine-coding candidates usually lose points.

Interview signals

  • State and behavior: Neutral → like → dislike → neutral gives counts 128/4 → 129/4 → 128/5 → 128/4.
  • Edge cases: Buttons expose selected text and aria-pressed, and can be activated by Enter/Space.
  • Explanation: Explain the state model and demonstrate the acceptance checks.

Time checkpoints

  1. 1

    0:00: Read the contract and inspect the fixtures.

  2. 2

    6:00: Complete the state and interaction handlers.

  3. 3

    13:00: Check keyboard use and boundary behavior.

  4. 4

    20:00: Run every acceptance check and explain tradeoffs.

Edge-case checklist

Neutral → like → dislike → neutral gives counts 128/4 → 129/4 → 128/5 → 128/4.
Repeated toggles and switching never drift from baseline plus the current reaction.
Queued toggles compute from the latest state; only one button can be pressed.
Buttons expose selected text and aria-pressed, and can be activated by Enter/Space.

Common mistakes

  • What changes when two devices vote as the same user?
SolutionRead-only · Live Preview

Technical Explanation

Model three legal states

One value (null, like, or dislike) makes double selection impossible. Two booleans permit an invalid fourth state.

Derive counts instead of adjusting them

Add one to the corresponding baseline count. Returning to neutral restores the baseline automatically. Never increment and decrement separate counters across multiple handlers.

Apply a transition

A click equal to the current reaction clears it; any other click replaces it. Use a functional setter so queued updates consume the latest state. This local exercise does not model server votes; that is a separate concurrency problem.

Interview Criteria

State and behavior

Neutral → like → dislike → neutral gives counts 128/4 → 129/4 → 128/5 → 128/4.

Edge cases

Buttons expose selected text and aria-pressed, and can be activated by Enter/Space.

Explanation

Explain the state model and demonstrate the acceptance checks.

Time Checkpoints

0:00

0:00: Read the contract and inspect the fixtures.

6:00

6:00: Complete the state and interaction handlers.

13:00

13:00: Check keyboard use and boundary behavior.

20:00

20:00: Run every acceptance check and explain tradeoffs.

Streak

0 days

Last active: Sign in to track

Progress

0%

0/0 solved

Submitted

0

Solutions pushed to review history.

More Machine Coding

View all Machine Coding →
Machine CodingMedium

React Tic-Tac-Toe Engine

Machine CodingMedium

Performant Image Slider

Machine CodingMedium

API Search and Render Image

Machine CodingEasy

Accessible React Tabs

Machine CodingMedium

Recursive File Explorer

Machine CodingEasy

Stopwatch

Related hubs

  • All machine coding
  • Frontend machine coding guide
  • React machine coding questions
  • UI coding interview questions
  • React UI interview questions
  • ByteDance interview
  • Facebook interview
  • Meta interview
  • TikTok interview