February 18, 2026
Slides: slides.com/joelross/info340wi26-interactive-react
onClick, onChange, onSubmitonClick={handleClick} not onClick={handleClick()}State tracks internal component data that changes over time:
const [count, setCount] = useState(0);
const handleClick = () => {
setCount(count + 1);
};
useState(initialValue) returns [stateVar, setterFunction]console.log in handlers shows old valuesForm inputs store their data in state, making React the source of truth:
const [inputValue, setInputValue] = useState('');
const handleChange = (event) => {
setInputValue(event.target.value);
};
return <input value={inputValue} onChange={handleChange} />;
value and onChange attributesonChange, updating state and re-rendering// Parent component
function App() {
const [items, setItems] = useState([]);
const addItem = (newItem) => {
setItems([...items, newItem]);
};
return (
<>
<AddForm onAdd={addItem} />
<ItemList items={items} />
</>
);
}
// Child component
function AddForm({ onAdd }) {
const handleSubmit = (event) => {
event.preventDefault();
onAdd(newItemData);
};
// ...
}
[stateVar, setter] for managing dynamic datavalue and onChange tied to state