React Hooks Error: Hooks can only be called inside the body of a function component

后端 未结 17 2118
旧巷少年郎
旧巷少年郎 2020-12-05 04:07

I am getting this error when using the useState hook. I have this in it\'s basic form, looking at the react docs for a reference, but am still getting this erro

17条回答
  •  隐瞒了意图╮
    2020-12-05 04:25

    found this workaround for react-hot-loader while that PR to fix it is inbound.

    Wrap the function that calls hooks in a React.memo, preventing a hot reload if it's unchanged.

    const MyFunc = React.memo(({props}) => {...

    Credit for solution: https://github.com/gatsbyjs/gatsby/issues/9489

提交回复
热议问题