lazy and suspence
Is lazy function supports named exports?
No, currently React.lazy
function supports default exports only. If you would like to import modules which are named exports, you can create an intermediate module that reexports it as the default. It also ensures that tree shaking keeps working and donβt pull unused components. Let's take a component file which exports multiple named components,
and reexport MoreComponents.js
components in an intermediate file IntermediateComponent.js
Now you can import the module using lazy function as below,
How do you memoize a component?
There are memoize libraries available which can be used on function components.
For example moize
library can memoize the component in another component.
Update: Since React v16.6.0, we have a React.memo
. It provides a higher order component which memoizes component unless the props change. To use it, simply wrap the component using React.memo before you use it.
OR