react-native - 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)
. .
解决方案
好的,我在这里犯了一个错误。我没有调用一个动作,而是调用了 reducer。
request: () => dispatch(HelpRedux.helpPostt()),
推荐阅读
- node.js - 为本地节点项目部署`index.html`与`npm start`之间的区别?
- python - 为什么数据帧上的 .dropna().apply() 确实有效?
- reporting-services - 无法使用报表生成器编辑旧的 SSRS 报表
- python - 如何使我的异步协程函数不阻塞?
- r - 为什么 SparkR(在数据块上)在使用 spark 数据帧时不显示摘要函数输出?
- c# - 将基类向下转换为派生的泛型 C#
- spring-boot - 如何修改 WebMVC.fn RouterFunction 响应的标头?
- css - 移动设备上的 Flipcard - 第一次点击不起作用
- android - 如何在 Android 11 中获取 dir 文件列表
- python - conda install python=3.8 需要几个小时