liveBook · Manning

Button

As explained in React Quickly, Second Edition

A button is an interactive user-interface control that can be activated to initiate an action or select an option.

A button starts an action when clicked. In React, a reusable Button component can wrap an HTML `<button>`, supplying consistent styling while its caller chooses the label and action. section 8.6

Two actions, one component

A counter can render `<Button label="Increment" handleClick={() => update(1)} />` and a second Button that calls `update(-1)`. Inside Button, `<button onClick={handleClick}>{label}</button>` connects each click to its action. This direct connection also passes the click event to `handleClick`. If callers should receive no event, use `onClick={() => handleClick()}` instead. section 8.6

Placement matters: a button inside a form submits that form by default. A submission can reload the page, even when the form has no inputs. Use that behavior for an intended form submission; otherwise, account for the default action. section 8.4.1 section 12.1.1

An icon button for a timer

A timer’s Button accepts `icon` and `label`, renders an image inside `<button title={label}>`, and forwards extra properties to the HTML button. Its parent changes the icon, label, and click handler according to whether the timer is running, displaying play or pause as appropriate. section 12.2.2 section 12.2.4

The same pattern extends to task controls: buttons edit or delete a task, while an icon button submits the add-task form. A separate menu example switches between Log In and Log Out buttons and conditionally shows a profile link; that trust-based switch is only a demonstration, not real authentication. section 13.2.4 section 11.5

Listing 12.5 src/Button.js in the simple timer
function Button({ icon, label, ...rest }) {               #1
  return (
    <button title={label} className="toggle" {...rest}>   #2
      <img src={`/icons/${icon}.svg`} alt={label} />
    </button>
  );
}
export default Button;

See how the timer’s reusable component puts a label and icon on an HTML button and forwards remaining properties. section 12.2.4

How React Quickly, Second Edition covers it

How deep it goes
Works through reusable components, callback forwarding, and default form submission, without descending into browser event internals.
Examples
Shows increment and decrement controls, play and pause icons, task-editing controls, and a Log In button.
What it assumes
Assumes basic JSX and component syntax while explaining the HTML form button’s default action directly.
What you can do after
Build it from scratch as a reusable React button that accepts a label and action, then apply it in larger interfaces.
How it connects
Connects buttons to React components, props, click handlers, state, forms, and conditional rendering.

Also explained in

Compare how 8 books explain button →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React Quickly, Second Edition. The section links point to the parts of the book it draws on.