function SettingsPanel({ filters }) {
const [brightness, setBrightness] = useState(0);
return (
<FilterSlider
name="Brightness"
value={brightness}
onChange={(val) => setBrightness(val)}
/>
);
}
function App() {
const [activeTool, setActiveTool] = useState('select');
return (
<>
<Toolbar
activeTool={activeTool}
onToolSelect={setActiveTool}
/>
<CanvasArea activeTool={activeTool} />
</>
);
}
Both Toolbar and Canvas need activeTool → state lives in App. App passes the value down and the setter function down. Children call the setter, App re-renders, both children get the new value.
// Wrong: mutating state
filterValues.brightness = 50;
// React doesn't know this changed!
// Right: creating new state
setFilterValues({
...filterValues,
brightness: 50
});
// React re-renders!
git switch -c bugfix/PIXELCRAFT-030-add-state
git add src/components/ src/App.jsx
git commit -m "Add useState to toolbar and sliders (PIXELCRAFT-030)"
git push origin bugfix/PIXELCRAFT-030-add-state
# PR → Review → Merge → Close ticket ✅
Reactive programming.
When state changes, the UI automatically reflects the new state. React's model: UI = f(state).