Hint
Smart vs dumb components — data fetching separated from rendering; largely replaced by hooks but the principle remains
The pattern separates data concerns (fetching, state) from UI concerns (rendering, styling):
// ❌ Old way — explicit Container component
function UserListContainer() {
const [users, setUsers] = useState([]);
useEffect(() => { fetchUsers().then(setUsers); }, []);
return ; // pass data down
}
function UserList({ users }) {
return users.map(u => );
}
// ✅ Modern way — custom hook achieves the same separation
function useUsers() {
return useQuery(['users'], fetchUsers);
}
// Presentational component stays the same
function UserList({ users }) {
return users.map(u => );
}
// Consuming component — much simpler
function UsersPage() {
const { data: users } = useUsers();
return ;
}
Still relevant principles: