taro dva-core 没有useDispatch ?



  • 在Taro添加dva npm是 dva-core dva-loading
    但是在使用react-hooks的时候
    import { useSelector, useDispatch } from 'dva-core';
    都是undefined
    请问如何解决。

    import Taro, { useState,useEffect } from '@tarojs/taro'
    import ComponentTest from '../components/ComponentTest';
    import { useSelector, useDispatch } from 'dva-core';
    
    // https://react-redux.js.org/next/api/hooks
    
    export default function Products() {
      console.info(`useDispatch: `, useDispatch);
      const dispatch = useDispatch();
      const products = useSelector(state => state.products);
      useEffect(() => {
        dispatch({
          type: 'user/effectsDemo',
        });
      },[]);
      const handleDelete = id => {
        dispatch({
          type: 'user/delete',
          payload: id,
        });
      };
      return (
        <div>
          <h2>List of Products</h2>
          {/* <ComponentTest onDelete={handleDelete} products={products} /> */}
        </div>
      );
    }
    




  • import { useSelector, useDispatch ,useStore } from '@tarojs/redux';
    就可以了。


登录后回复