Skip to content

Commit 348c1ca

Browse files
committed
Add React new features
1 parent cab1706 commit 348c1ca

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@
234234
|218| [How to pass numbers to React component?](#how-to-pass-numbers-to-react-component?)|
235235
|219| [Do I need to keep all my state into Redux? Should I ever use react internal state?](#do-i-need-to-keep-all-my-state-into-redux-should-i-ever-use-react-internal-state)|
236236
|220| [What is the purpose of registerServiceWorker in React?](#what-is-the-purpose-of-registerserviceworker-in-react)|
237+
|221| [What is React memo function?](#what-is-react-memo-function)|
238+
|222| [What is React lazy function?](#what-is-react-lazy-function)|
237239

238240
## Core React
239241

@@ -3782,4 +3784,27 @@
37823784
37833785
ReactDOM.render(<App />, document.getElementById('root'));
37843786
registerServiceWorker();
3785-
```
3787+
```
3788+
221. ### What is React memo function?
3789+
3790+
Class components can be restricted from rendering when their input props are the same using **PureComponent or shouldComponentUpdate**. Now you can do the same with function components by wrapping them in **React.memo**.
3791+
```jsx
3792+
const MyComponent = React.memo(function MyComponent(props) {
3793+
/* only rerenders if props change */
3794+
});
3795+
```
3796+
222. ### What is React lazy function?
3797+
The React.lazy function lets you render an dynamic import as a regular component. It will automatically load the bundle containing the OtherComponent when the component gets rendered. This must return a Promise which resolves to a module with a default export containing a React component.
3798+
```jsx
3799+
const OtherComponent = React.lazy(() => import('./OtherComponent'));
3800+
3801+
function MyComponent() {
3802+
return (
3803+
<div>
3804+
<OtherComponent />
3805+
</div>
3806+
);
3807+
}
3808+
```
3809+
**Note:**
3810+
React.lazy and Suspense is not yet available for server-side rendering. If you want to do code-splitting in a server rendered app, we still recommend React Loadable.

0 commit comments

Comments
 (0)