Professional Documents
Culture Documents
Thinking in Components. How I Think About Composing A Used... by Tom Buyse
Thinking in Components. How I Think About Composing A Used... by Tom Buyse
Thinking in Components
How I think about composing a user interface
1 of 9 17.01.21, 19:50
Thinking in Components. How I think about composing a user… |... https://medium.com/better-programming/thinking-in-components...
The Example
Let’s say I’m tasked with building an interface in which an
administrator can manage the users of an application. It should
be possible to view basic information, create a new user, and
edit or delete current ones. Above all, a search function must be
included to make finding users even easier.
All in all, this is a basic CRUD example that you could find in
most applications. In the image below, you can get an idea of
what this would look like:
2 of 9 17.01.21, 19:50
Thinking in Components. How I think about composing a user… |... https://medium.com/better-programming/thinking-in-components...
User page
User list
User item
You might ask, “What about the search input, button, and
backlink?” These are equally important, but I consider these
reusable components. It’s important to scan a design for these
because we want to make them abstract enough so we could use
them in other places as well. We might want to start creating
these first before we can compose this page.
3 of 9 17.01.21, 19:50
Thinking in Components. How I think about composing a user… |... https://medium.com/better-programming/thinking-in-components...
Responsibilities
Example divided into main components.
User page
This is the main container in which all our other components
will be nested. Its purpose is to create some structure by
containing the other components. It will also be responsible for
fetching the users. Since both the user page and the user list
need access to this data, it makes sense to keep it at the top
level.
User list
This component is responsible for displaying the list of users.
User item
This component displays the details of a user and handles the
edit and delete actions.
4 of 9 17.01.21, 19:50
Thinking in Components. How I think about composing a user… |... https://medium.com/better-programming/thinking-in-components...
Data Flow
Before we begin programming this user interface, let’s also first
think about the data flow in this page. Below is a visualisation of
how I would propose the data is going to flow through the
application:
It isn’t as error-prone.
5 of 9 17.01.21, 19:50
Thinking in Components. How I think about composing a user… |... https://medium.com/better-programming/thinking-in-components...
6 of 9 17.01.21, 19:50
Thinking in Components. How I think about composing a user… |... https://medium.com/better-programming/thinking-in-components...
State Management
What if this page continues to grow and contains more child
components that also need to access user data? This is the
tipping point for adding a library to manage this state.
The reason why all components are connected with the state is
to reduce prop drilling (passing props multiple levels down).
Additionally, this is considered a best practice in most libraries
for performance reasons. Fewer components will need to re-
render when the data changes.
7 of 9 17.01.21, 19:50
Thinking in Components. How I think about composing a user… |... https://medium.com/better-programming/thinking-in-components...
Conclusion
Hopefully, this article has given you some insights on how I go
about determining the components and state within an
application.
Resources
https://kentcdodds.com/blog/prop-drilling
https://redux.js.org/style-guide/style-guide/
8 of 9 17.01.21, 19:50
Thinking in Components. How I think about composing a user… |... https://medium.com/better-programming/thinking-in-components...
9 of 9 17.01.21, 19:50