undefined不是评估"this.props.dispatch"的函数



我尝试测试redux。我有重定向到testReDux的组件主体。当单击按钮时,TestReDux组合进行调度并重定向到TestReDux2。

testredux和testRedux2相同,我做了一个副本/粘贴,只需更改值即可。testReDux派发正确,但TestReDux2触发错误。

您知道问题的原因是什么?

// TestRedux
import React from 'react';
import { View, Text, Button, Alert } from 'react-native';
import { ADD_RES } from "../Constants/action-types";
import {addResa} from "../Actions/actions";
import { connect } from 'react-redux'
import Store from '../Store/store'

const mapStateToProps = state => ({ date: state.date }) 

export class TestRedux extends React.Component {
  render() {
    this.props.dispatch(addResa(1));
    return (
      <View>
         <Button
              onPress={() => {  this.props.navigation.navigate('TestRedux2')  }}
              title='test'
          />
      </View>
    )
  }
}

export default connect(mapStateToProps)(TestRedux)
// TestRedux2
import React from 'react';
import { View, Text, Button, Alert } from 'react-native';
import { ADD_RES } from "../Constants/action-types";
import {addResa} from "../Actions/actions";
import { connect } from 'react-redux'
import Store from '../Store/store'
const mapStateToProps = state => ({ date: state.date }) 
export class TestRedux2 extends React.Component {
  render() {
    this.props.dispatch(addResa(2));
    return (
      <View>
         <Button
              onPress={() => {  this.props.navigation.navigate('TestRedux')  }}
              title='test2'
          />
      </View>
    )
  }
}

export default connect(mapStateToProps)(TestRedux2)

商店是:

import { createStore } from "redux"; // without redux persist
import { persistCombineReducers } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
import resaReducer from "../Reducers/resaReducer";
const rootPersistConfig = {
  key: 'root',
  storage: storage
}
const Store = createStore(persistCombineReducers(rootPersistConfig, {resaReducer}))
export default Store;
````

派遣操作或通过null进行连接。看看问题是否继续。

export default connect(mapStateToProps)(TestRedux2)

export default connect(mapStateToProps, null)(TestRedux2)

相关内容

  • 没有找到相关文章

最新更新