Efficient way to organise UI components
Alex Li
Older versions (before October, 2015)
Class component only
0.14.0 (October, 2015)
Functional component was added into React
16.8.0 (February, 2019)
Hooks were added into React
17.0.0 (October, 2020)
Concurrent mode (time slicing, suspense)
Functional Components are simple plain javascript functions which return JSX.
const Header = (props) => (
<div>
<h1>{props.title}</h1>
<h2>{props.subtitle}</h2>
</div>
);
<Header title="Title"
subtitle="Sub title"
/>
Stateful
Lifecycle methods
Rely on this
Error boundary
Stateful
Lifecycle methods
Rely on this
Error boundary
React hooks make fill in the gaps between functional component and class component and even beyond it.
Hooks are a set of functions which can only be used by functional components for
Reusable code pattern should always be concerned
In functional programming, there is a well-known concept named high-order functional. HOC is a similar thing in react. A HOC is usually a:
withErrorState(withAuth(withAdContext(withDeviceSize(withResizeable(withDraggable(...))))))
Render props is a similar pattern with HOC but with some differences:
UI=F(props, H1(param), H2(param),...Hn(param))
Do you think virtual DOM fast?
Just like GC technology, Virtual dom technology is aiming to find out a balanced solution between development experience and render performance. The key to success in react application performance is reduce unnecessary re-rendering