How to fix the error “react use hook cannot be called inside a callback function” using react?

前端 未结 2 1077
半阙折子戏
半阙折子戏 2021-01-25 04:14

i am using useHook named useGetCompanyByItemId in the return statement.

and so i am getting the error "react hook cannot be called in a callback function"

<
2条回答
  •  情歌与酒
    2021-01-25 04:55

    Extract this logic to a component

    function Item({ item, isSharedItem }) {
      const company = useGetCompanyByItemId(item.id);
      return (
        <>
          {isSharedItem && (
            
    company
    )} ); }

    and then use it in your loop

    springProps.map((index) => {
      ...
      return 
    

提交回复
热议问题