React Foundations·Practice drills 8

Drill 20: Make it smaller — Props and composition

Write a smaller version of the example that keeps the core idea.

Intermediate 5 min read Lesson 202 of 300 Challenge included
What you will be able to do
  • Write a smaller version of the example that keeps the core idea.

Practice task

Write a smaller version of the example that keeps the core idea.

Badge.tsxTSX
import type { ComponentProps, ReactNode } from 'react'

type BadgeProps = {
  tone?: 'neutral' | 'success' | 'danger'
  children: ReactNode
}

function Badge({ tone = 'neutral', children }: BadgeProps) {
  return <span className={'badge badge-' + tone}>{children}</span>
}

type ButtonProps = ComponentProps<'button'>

function Button(props: ButtonProps) {
  return <button {...props} />
}
Your turn

Write your answer

Easy

Write a smaller version of the example that keeps the core idea.

TEXT · starter
Your answer…
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 202 of 300 · 0% of course