首页 > 解决方案 > redux 给出“不是函数”错误 - redux sauce

问题描述

我用的是redux酱。当我调度一个动作时,它给了我“_HelpRedux.default.request is not a function”错误。任何帮助表示赞赏。我怎样才能使它正确?我没主意了。提前致谢

帮助Redux.js

import { createReducer, createActions } from 'reduxsauce';
import Immutable from 'seamless-immutable';

const { Types, Creators } = createActions({
  helpPostt: null,
  dashboardRequest: ['data'],
})

export const HelpTypes = Types
export default Creators

export const INITIAL_STATE = Immutable({
  fetching: false,
  data: null,
})

export const helpRequestPost = (state) => {
  return state;
}

export const request = (state) => state.merge({ fetching: true });

export const reducer = createReducer(INITIAL_STATE, {
  [Types.HELP_POSTT]: helpRequestPost,
  [Types.DASHBOARD_REQUEST]: request,
})

HelpScreen.js

import React, { Component } from 'react'
import { View, Text, KeyboardAvoidingView, ScrollView, TouchableOpacity, TextInput, Linking, Platform } from 'react-native'
import { connect } from 'react-redux';
import HelpRedux from '../Redux/HelpRedux';

class HelpScreen extends Component {

  tryLogin = () => {
    this.props.request(); //_HelpRedux.default.request is not a function
    //this.props.helpRequestPost(); //_HelpRedux.default.helpRequestPost is not a function
  }

  render () {
    console.log("help", this.props);
    return (
      <View>
        <TouchableOpacity onPress={this.tryLogin}>
            <Text>abc</Text>
        </TouchableOpacity>
      </View>
    )
  }
}

const mapDispatchToProps = (dispatch) => {
  return {
    request: () => dispatch(HelpRedux.request()),
    helpRequestPost: (key) => dispatch(HelpRedux.helpRequestPost(key)),
  }
}

export default connect(null, mapDispatchToProps)(HelpScreen)

. .

标签: react-nativereduxreact-redux

解决方案


好的,我在这里犯了一个错误。我没有调用一个动作,而是调用了 reducer。

request: () => dispatch(HelpRedux.helpPostt()),

推荐阅读