ice-lab / icestore

🌲 Simple and friendly state for React
MIT License
397 stars 35 forks source link

Bug: 在 umi 中使用 icestore #139

Closed qqqdu closed 2 years ago

qqqdu commented 2 years ago

@ice/store version:

Steps To Reproduce

  1. 按照文档demo操作

const counter = { state: 0, reducers: { increment: (prevState) => prevState + 1, decrement: (prevState) => prevState - 1, }, effects: () => ({ async asyncDecrement() { await delay(1000); this.decrement(); }, }), };

const { useModel } = createStore({ counter, });

function FunctionComponent() { const [state, dispatchers] = useModel('counter');

return

{state}

; }

<!--
  Your bug will get fixed much faster if we can run your code and it doesn't
  have dependencies other than @ice/store. Issues without reproduction steps or
  code examples may be immediately closed as not actionable.
-->

Link to code example:

<!--
  Please provide a CodeSandbox (https://codesandbox.io/s/new), a link to a
  repository on GitHub, or provide a minimal code example that reproduces the
  problem. You may provide a screenshot of the application if you think it is
  relevant to your bug report. Here are some tips for providing a minimal
  example: https://stackoverflow.com/help/mcve.
-->

## The current behavior

TypeError: Cannot read property 'store' of null useSelector ./node_modules/@ice/store/node_modules/react-redux/es/hooks/useSelector.js:126:33 123 | } 124 | 125 | var _useReduxContext = useReduxContext(),

126 | store = _useReduxContext.store, | ^ 127 | contextSub = _useReduxContext.subscription; 128 | 129 | var selectedState = useSelectorWithStoreAndSubscription(selector, equalityFn, store, contextSub);

useModel('counter');

执行这里报错 版本是 1.4.3

luhc228 commented 2 years ago

要包裹 Provider 组件 https://github.com/ice-lab/icestore/blob/master/docs/api.md#provider

qqqdu commented 2 years ago

要包裹 Provider 组件 https://github.com/ice-lab/icestore/blob/master/docs/api.md#provider

哦哦哦,可以了,tks