← Back to Week 7

Interactive React

February 18, 2026

Topics Covered

Slides: slides.com/joelross/info340wi26-interactive-react

React Events

State with useState()

State tracks internal component data that changes over time:

const [count, setCount] = useState(0);

const handleClick = () => {
  setCount(count + 1);
};

State vs Props

Controlled Forms

Form 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} />;

Lifting State Up

// 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);
  };
  // ...
}

Project Draft 2

Key Concepts

Resources