use memo in react js code example
Example 1: useRef
function TextInputWithFocusButton() {
const inputEl = useRef(null);
const onButtonClick = () => {
inputEl.current.focus();
};
return (
<>
<input ref={inputEl} type="text" />
<button onClick={onButtonClick}>Focus the input</button>
</>
);
}
Example 2: import React, { memo } from 'react';
const MyComponent = React.memo(function MyComponent(props) {
});
Example 3: how to add react.memo in export list
export const MemoMainPostTopic = React.memo(MainPostTopic);
const MainPostTopic = memo(() => {
...
})
export { MainPostTopic };