A Map to Navigate the React Ecosystem
THIS IS ABSOLUTELY AMAZING but Sara Vieira has accomplished what no developer, myself included, has ever accomplished before: motivated me to use React for fun.
đ The Opinionated Guide to React, by Sara Vieira
This book is ridiculously empowering â for me, where I am in my learning, right now. Itâs not a resource to learn React from scratch, nor a deep dive into topics. But it provides a map of the ecosystem and was exactly the overview I was missing. Sara is clear that she is sharing her opinion, and this focus is a lot more helpful for me than having to deal with âhere are ALL my optionsâ.
The code examples are super useful. Limited in scope, but every one a complete application on itâs own. Never found that before. Iâve only worked in fully fledged applications with all the bells and whistles â or seen lone snippets of code in tutorials that float around with zero context.
Check out The Opinionated Guide to React đ for a full summary of the topics covered in the book. The notes below are a subset, my personal takeaways and thoughts.
Structuring files and folders
pages/ our main pages (with sections and modules)
components/ things to be reused multiple places
utils/ stash complicated functions away here
assets/ for images and icons
I like the simplicity in starting with these four. For applications in general, regardless of React, it is easy to get lost in âmore categories must be betterâ when one long list of components and a single list of pages is much easier than attempts to maintain levels between the two.
- name files
index.js
and let folder names do the talking - export named components for easier debugging (eslint rule)
eslint-config-react-app
can also be used outside CRA and âsaves you from all the common pitfalls without forcing you into a particular styleâ
State management
Whoa. I had heard about different libraries with their pros and cons. But I hadnât seen the library option described in relation to the existing parts of React like Sara explains nicely.
âcontext is perfect for many use cases where you need state spread around your application, but that state is never going to grow into a big ball of complicated sadnessâ
useState
can handle simple state locally at component levelContext
is also built in, works globally and might be enough- âŠand for more complex use cases: you want a state management library
At CodeSandbox, we have been using Overmind for a while, and we were using its predecessor Cerebral before that. It is honestly a breath of fresh air when it comes to state management: it's simpler than most but super powerful and super extensible. You can use Overmind in big applications with minimal boilerplate.
Project starters
I knew about all these, but hadnât seen them compared as straight forward as this before â or described as âproject startersâ, which provides context for my mental model of what and why.
- Create React App with
react-scripts
to abstract away a lot of dependencies, great for a quick start, but beware; you have no access to Webpack or a Babel config - Next is set up for server-side rendered out of the box and you can change the Babel config
- Gatsby is a static site generator to export HTML, a lot of options for tools and plugins
Itâs great to have these frameworks, but I want to learn setting up an application with my own build toolchain. Possibly famous last words coming up; but âhow hard it can be?!â
Potential problems and suggested packages
- Routing: React Router
- State management: Overmind
- Animation: Framer Motion
- Styling: styled-components
- Forms: Formik
- Dates: date-fns
- GraphQL: React Apollo
The explanations about which problems I might want to solve in my application were really helpful. Sara covers which packages she often uses to solve those problems, and also when you need to look further. (In addition to this list, the book covers UI toolkits, icons and component playground.)
Hooks
Saraâs examples on hooks are super approachable đ„° and CodeSandbox helps a lot. Much less like the âhow to draw an owlâ tutorials on hooks I usually come across. I am looking forward to coding up these examples for myself and playing around with them.
Deployments
Step by step to deploy all three project starters on Netlify and Vercel. Wohoo!
These are my personal notes from reading the book now. But The Opinionated Guide to React itself is going to be updated as the ecosystem keeps evolving and I look foreward to following along when Saraâs recommendations change!