conventions.io

Tech Challenge

2026-08-30

⚛️

Daily Tech Challenge

React

medium
Question 1 of 5

Lamp and Fan both call the SAME custom hook, useToggle. The user clicks the lamp button exactly once. What do the two buttons display afterwards?

Example
import { useState } from 'react';

function useToggle(initial) {
  const [on, setOn] = useState(initial);
  return [on, () => setOn(v => !v)];
}

function Lamp() {
  const [on, toggle] = useToggle(false);
  return <button onClick={toggle}>lamp {String(on)}</button>;
}

function Fan() {
  const [on, toggle] = useToggle(false);
  return <button onClick={toggle}>fan {String(on)}</button>;
}

// rendered as: <><Lamp /><Fan /></>

Sunday, August 30, 2026 · A new challenge drops every day