dvajs / dva

🌱 React and redux based, lightweight and elm-style framework. (Inspired by elm and choo)
https://dvajs.com/
MIT License
16.24k stars 3.17k forks source link

import { useSelector } from 'dva'; is not work! #2466

Closed AlonDeng closed 2 years ago

AlonDeng commented 2 years ago

What happens?

無法引入 redux hook

image

athrunsun commented 2 years ago

你用的是哪个版本的dva?

hideInEye commented 2 years ago

那个版本也不可以 dva没有对react-redux 升级 所以无法使用,现在useSelector,useDispatch 都在umi中集成.并没有在dva中

athrunsun commented 2 years ago

我用的2.6.0-beta.22,是没问题的。

hideInEye commented 2 years ago

我用的2.6.0-beta.22,是没问题的。

最新版本确实有但是需要provide包装组件.

athrunsun commented 2 years ago

但是需要provide包装组件

没明白你的意思,能说明一下吗?

hideInEye commented 2 years ago

但是需要provide包装组件

没明白你的意思,能说明一下吗?

我在用webpack+react+dva 使用时dva默认安装版本是没有hooks 语法的,但是我升级为最新版beta版本时.他会让我用Provide上下文包装给 react 组件. 不然是无法使用的. image 具体请看codeSandbox:https://codesandbox.io/s/amazing-kirch-clk9b?file=/src/App.js

athrunsun commented 2 years ago

@juvenile-bin 你的这个repo里引用的dva版本不对,而且你也并没有用到dva啊?

就算不用dva,也需要在index.js里初始化一个redux store并加上一个<Provider>

import { Provider } from 'react-redux';

// 初始化redux store
const store = ...

ReactDOM.render(
  <StrictMode>
    <Provider store={store}>
      <App />
    </Provider>
  </StrictMode>,
  rootElement
);
hideInEye commented 2 years ago

@juvenile-bin 你的这个repo里引用的dva版本不对,而且你也并没有用到dva啊?

就算不用dva,也需要在index.js里初始化一个redux store并加上一个<Provider>

import { Provider } from 'react-redux';

// 初始化redux store
const store = ...

ReactDOM.render(
  <StrictMode>
    <Provider store={store}>
      <App />
    </Provider>
  </StrictMode>,
  rootElement
);

是的

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.