React Checkbox

React Checkbox

Checkboxes in React are handled slightly differently than your standard text inputs. Instead of targeting e.target.value, you must use e.target.checked to determine the active boolean state of the checkbox.

Managing Checkbox State

import { useState } from 'react';

function CheckboxForm() { const [isChecked, setIsChecked] = useState(false); return <input type="checkbox" checked={isChecked} onChange={(e) => setIsChecked(e.target.checked)} />; }