AI Hints
Home›React Tutorial›Cheat Sheets
React · Lesson 112 of 120

Cheat Sheet: Components

The essentials.

⏱ 2 min read▶ Video at 1:32:16🎓 Free
Watch this lesson in the React courseWatch on YouTube ↗Full React course

Let's pull everything together into quick reference sheets. First, components and JSX.

  • Quick reference
  • Components
  • JSX

Components and JSX

A component is a function that returns JSX. Props pass data in, and children pass content in. Curly braces hold expressions. Map renders lists, with a key for each item. And conditions use and, or the ternary.

NeedWrite
A componentfunction Card(props) { return <div /> }
Props<Card title="Hi" />
Children<Card>...</Card>
Expressions{price * 1.2}
Lists{items.map(i => <li key={i.id} />)}
Conditions{ok && <p />} {a ? <A /> : <B />}

Events and forms

Pass functions to event props. Controlled inputs pair value with on change. Checkboxes use checked. And forms handle on submit, calling prevent default first.

NeedWrite
ClickonClick={handleClick}
Text inputvalue={v} onChange={e => setV(e.target.value)}
Checkboxchecked={c} onChange={e => setC(e.target.checked)}
FormonSubmit={e => { e.preventDefault(); }}

Summary

That's components, props, lists, conditions, and forms on one page. Next, the hooks cheat sheet.

Key takeaways
  • Components
  • Props
  • Forms
Next up: Cheat Sheet: Hooks — the essentials