Answers for "use memo in react js"

32

useRef

/*
	A common use case is to access a child imperatively: 
*/

function TextInputWithFocusButton() {
  const inputEl = useRef(null);
  const onButtonClick = () => {
    // `current` points to the mounted text input element
    inputEl.current.focus();
  };
  return (
    <>
      <input ref={inputEl} type="text" />
      <button onClick={onButtonClick}>Focus the input</button>
    </>
  );
}
Posted by: Guest on March-29-2020
10

react memo

function MyComponent(props) {
  /* render using props */
}
function areEqual(prevProps, nextProps) {
  /*
  return true if passing nextProps to render would return
  the same result as passing prevProps to render,
  otherwise return false
  */
}
export default React.memo(MyComponent, areEqual);
Posted by: Guest on June-07-2020
2

react memo

/* this is for es6 onward */
/* React.memo is the new PureComponent */

import React, { memo } from 'react'

const MyComponent = () => {
 return <>something</>
}

export default memo(MyComponent)
Posted by: Guest on May-29-2021
1

import React, { memo } from 'react';

const MyComponent = React.memo(function MyComponent(props) {
  /* only rerenders if props change */
});
Posted by: Guest on October-03-2020
0

how to add react.memo in export list

export const MemoMainPostTopic = React.memo(MainPostTopic);
 

//or

const MainPostTopic = memo(() => {
 ...
})
export { MainPostTopic };
Posted by: Guest on July-12-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language