← React Beginner Questions - Set 1 Q3

What are components in React?

React Beginner Questions - Set 1

A component is a function that returns JSX. Composition — components using components — is the whole architecture.

Example

function Avatar({ name }) {
  return <span className="avatar">{name[0]}</span>;
}

function UserCard({ user }) {
  return (
    <article className="card">
      <Avatar name={user.name} />
      <h3>{user.name}</h3>
      <p>{user.role}</p>
    </article>
  );
}

export default function Team({ users }) {
  return <>{users.map(u => <UserCard key={u.id} user={u} />)}</>;
}

What to notice

← Back to the question list