facebookarchive / redux-react-hook

React Hook for accessing state and dispatch from a Redux store
MIT License
2.16k stars 103 forks source link

Hooks can only be called inside the body of a function component. #43

Closed lichspace closed 5 years ago

lichspace commented 5 years ago

include react with

<script src="/js/lib/react.production.min.js"></script>
<script src="/js/lib/react-dom.production.min.js"></script>

include redux-react-hook with webpack import {StoreContext,useMappedState,useDispatch} from 'redux-react-hook';

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

i find _nodemodules/redux-react-hook/dist/index.js has code

var react = require('react'); i think this cause the error

I resolve this with:copy redux-react-hook/dist/index.js to my project and modify

var react = React;//from window.React

so, i want ask has a better way?

ianobermiller commented 5 years ago

https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react

You likely have two copies of React, the one you are including manually and the one packaged by webpack. You can remove the script tags.