Interactivity, State, and Hooks

At this point, React has taken over part of our page and is drawing the seats, which is nice enough, but we’d like it to, you know, react to something. We’d like to have a little interactivity.

In React, you can use JSX to specify event handlers on React elements in much the same way you would when writing old-school JavaScript embedded in HTML. The problem is how to make changes to our components as a result of those events. As mentioned, the props we pass into each component are immutable, which means if we want to change something about a component, we can’t use props. React uses the term state to refer to the parts of a component that change and trigger an update to how the component is displayed when they ...

Get Modern Front-End Development for Rails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.