We're ready for the next React
I really enjoy developing with React and I use it for all sorts of side-projects and at work too. Not only in our flagship product but for prototyping new ideas.
The past
The first time I heard about React I didn't quite get it and ended up dismissing it.
A declarative paradigm that makes it easier to reason about your application?
A JavaScript library (not a framework!) for building user interfaces… I'm sure it's great but what are you really talking about? An XML-like syntax called JSX? Inline styles? Turns out these people knew what they were doing and React ended up making a big impact and influencing how we do front-end development.
The present
Fast-forward to 2017 and we have React 16, which not only brought new features but also included a complete rewrite of the core architecture, codenamed "Fiber".
Fiber introduced new capabilities to React, such as error boundaries and fragments, but is not being utilized to its full potential in version 16. In the announcement post you can read:
Perhaps the most exciting area we’re working on is async rendering — a strategy for cooperatively scheduling rendering work by periodically yielding execution to the browser. The upshot is that, with async rendering, apps are more responsive because React avoids blocking the main thread.
We think async rendering is a big deal, and represents the future of React.
While React was maturing, the ecosystem surrounding it was evolving in many ways. One big part of this evolution was webpack, which has been widely adopted by the community.
One of the most compelling features of webpack is code splitting. It basically allows you to split your code into various bundles. You can manually split your code using multiple entry points. And more interestingly, with dynamic imports you can split code via function calls within modules. This can be very powerful and quite trivial to use. Create React App supports this out-of-the-box and projects like react-loadable
make it even easier:
import Loadable from 'react-loadable';
import Loading from './my-loading-component';
const LoadableComponent = Loadable({
loader: () => import('./my-component'),
loading: Loading,
});
export default class App extends React.Component {
render() {
return <LoadableComponent/>;
}
}
The future
Speed isn't everything and too much asynchronous rendering can actually worsen the user experience. No one likes loading states and rendering pieces of your app asynchronously brings some new challenges.
I maintain JS.coach and React.parts and thanks to it I end up reviewing many packages and reading a lot of tweets from the community. I have been made more aware of this problem thanks to a series of tweets by Andrew Clark, one of the key engineers that worked on Fiber.
A thought exercise: If code-splitting is so great, and bundlers like Webpack make it easy, why don't we code-split every component by default?
— Andrew Clark (@acdlite) February 11, 2018
(This is not a trick question)
Hint: https://t.co/zlD8oxgmII
— Andrew Clark (@acdlite) February 11, 2018
He later gave an example of how native apps solve this:
One reason iOS feels so much nicer than the web: fewer unnecessary loading states. Look what happens when you tap an option in the Settings app: rather than transition immediately and show a spinner, it pauses for a moment until the view is ready. pic.twitter.com/Rt4uWiJW7K
— Andrew Clark (@acdlite) January 20, 2018
This kind of behavior is not trivial to accomplish today with React. We may need a paradigm shift to actually take our web interfaces to the next level.
But thankfully it seems the React team is already on it.
Using a new strange API. I never felt this productive using React before. You’re going to hate it, then you’re going to love it. Will spill some beans in a week at @jsconfis
— Dan Abramov (@dan_abramov) February 24, 2018
A certain upcoming feature, in particular, is really hard to explain without seeing a live demo with code. Abstract explanations end up creating more confusion. You need to see the real thing. Stay tuned for @dan_abramov's talk this week at @jsconfis! https://t.co/uXsEY3bHWT
— Andrew Clark (@acdlite) February 26, 2018
I'm grateful for all the work these individuals share and I couldn't be more excited about front-end development. I'll definitely be watching the stream March 1st.