T
T
The_good_game2021-09-30 14:56:22
React
The_good_game, 2021-09-30 14:56:22

Why isn't the second argument being called inside React.memo()?

I was expecting that after the component is clicked, the check function inside React.memo() will be executed and it will not update. But this function is not executed, and I can't figure out what's wrong.

const Item = styled.div`
  //styles
`;

const Cell = (props) => {
  const [isSelected, setIsSelected] = useState(false);

  return (
    <Item onClick={() => setIsSelected(!isSelected)} status={{key: isSelected}} />
  )
}

const check = (prevProps, props) => prevProps === props;

const memoComp = React.memo(Cell, check)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-09-30
@The_good_game

We open the documentation and see that

React.memo only affects prop changes. If a functional component is wrapped in React.memo and uses useState , useReducer , or useContext , it will re-render when the state or context changes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question