A Component Doesn't Have to Be Dumb to Be Reusable
There's a long-running idea in frontend architecture:
Keep components dumb.
Let them receive data, render the UI, and leave everything else to something higher up the tree.
It sounds clean. And often, it is.
But there's a trade-off we don't always consider:
Making a component simpler can make the surrounding architecture more complicated.
Let's look at both approaches.
π΄ The Problem
Imagine a component that displays a list of users.
It needs to fetch the data, filter the results, and render them.
One approach is to put everything inside UserList .
function UserList () { const [ users , setUsers ] = useState < User [] > ([]); const [ query , setQuery ] = useState ( "" );
useEffect (() => { getUsers (). then ( setUsers ); }, []);
const filteredUsers = useMemo ( () => users . filter (( user ) => user . name . includes ( query )), [ users , query ], );
return ( < section > < input value = { query } onChange = { ( event ) => setQuery ( event .β¦