developit / preact-redux

:loop: Preact integration for Redux (no shim needed!)
https://npm.im/preact-redux
MIT License
288 stars 27 forks source link

Uncaught TypeError: store.getState is not a function #40

Closed higimo closed 5 years ago

higimo commented 5 years ago
Uncaught TypeError: store.getState is not a function
    at Object.runComponentSelector [as run] (preact-redux.esm.js?1530:372)
    at Connect.initSelector (preact-redux.esm.js?1530:525)
    at new Connect (preact-redux.esm.js?1530:466)
    at createComponent (preact.js?10a9:214)
    at renderComponent (preact.js?10a9:280)
    at renderComponent (preact.js?10a9:284)
    at setComponentProps (preact.js?10a9:248)
    at buildComponentFromVNode (preact.js?10a9:339)
    at idiff (preact.js?10a9:134)
    at diff (preact.js?10a9:109)
import { Provider, connect } from 'preact-redux';
import { h, render } from 'preact';

const Main = () => (
    <Provider store={store}>
        <Child />
    </Provider>
);

const Child = connect(
    state => state
)( ({ text, setText }) => (
    <input value={text} onInput={e => setText(e.target.value)} />
) );

render(<Main />, document.body);
"devDependencies": {
    "eslint": "^4.5.0",
    "eslint-config-synacor": "^1.1.0",
    "if-env": "^1.0.0",
    "preact-cli": "^2.0.0"
  },
  "dependencies": {
    "http-build-query": "^0.7.0",
    "preact": "^8.2.1",
    "preact-compat": "^3.17.0",
    "preact-redux": "^2.0.3",
    "redux": "^4.0.1"
  }
fjorgemota commented 5 years ago

Are you importing and/or creating the Redux store in the store variable correctly? I see you passing it as a prop to <Provider> but it doesn't appear on the file you mentioned...and if it's undefined then obviously that error will occur because store isn't initialized by preact-redux nor redux automatically.

Like it's mentioned on the README, it's suggested that you check Usage with React on Redux's docs to understand definitely what's needed to make use of this package.

higimo commented 5 years ago

this my mistake, version redux, preactm and other incompatible.=(