Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Well, it's only efficient if the component which renders each element in the list gets a stable key AND is React.memo() AND the props passed to the components do not make the React.memo() pointless.

For example the following will not be particularly efficient, because a fresh callback is passed to the component on each render.

  <>
    {array.map((data) => (
      <SomeComponent
        data={data}
        onClick={() => { alert('nope'); }}
      />
    )}
  </>


That's what useCallback is for. And it really depends on how heavy the child components are on whether all this makes a noticeable difference.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: