Tsallaka zuwa abun ciki
Justice Tech School

Container and Presentational

Separate data logic from display components.

Example
function UserList({ users }) {
  return <ul>{users.map((u) => <li key={u.id}>{u.name}</li>)}</ul>;
}
function UserListPage() {
  const [users, setUsers] = useState([]);
  useEffect(() => { fetch("/api/users").then((r) => r.json()).then(setUsers); }, []);
  return <UserList users={users} />;
}

Exercise

Pure display.

A  component only renders

Quiz Test

What does a presentational component do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.