更改文本时未定义错误不是功能

时间:2018-10-08 11:03:12

标签: react-native react-redux react-native-android

我正在尝试增量和减量教程。当我在textinput上输入数字时,此值将反映到给定的此文本中。但是我遇到了错误。错误提示

undefined is not a function(evaluating 'this.props.counterSet(count)')

这些是我尝试过的代码。谁能告诉我我在哪里做错了。

谢谢

- App
  -Actions
    -ActionTypes.js
    -CounterAction.js
  -Reducers
    -counterReducer.js
  app.js

counterReducer.js

export default (state = 0, action) => {
    switch (action.type) {
        case 'SET':
            return action.payload;
        default:
            return state;
    }
}

counterAction.js

export const counterSet = (receivedNumber) => {
    return {
        type: 'SET',
        payload: receivedNumber
    }
}

ActionTypes.js

export * from './CounterAction';

app.js

import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, TextInput, View, Button } from 'react-native';
import { connect } from 'react-redux';
import { counterSet } from './Actions/ActionTypes';

class App extends Component {
    constructor(props) {
        super(props);
        this.state = {
            count: 0
        };
        this.onChangeText = this.onChangeText.bind(this);
    }

    onChangeText(number) {
        let count = parseInt(number);
        // alert("inside", count);
        this.props.counterSet(count);
    }

    render() {
        return (
            <View style={styles.container}>
                <TextInput
                    style={{ width: 40, height: 40, borderWidth: 1 }}
                    onChangeText={this.onChangeText}
                    value={this.props.count.toString()}
                />
                <View style={styles.countViewStyle}>
                    <Text style={styles.welcome}>
                        {this.props.count}
                    </Text>
                </View>
            </View>
        );
    }
}

function mapStateToProps(state) {
    return {
        count: state
    }
}
export default connect(mapStateToProps, { counterIncrement, counterDecrement, counterClear, counterSet })(App);

1 个答案:

答案 0 :(得分:1)

更改导入

export * from './CounterAction';

export { counterSet } from './CounterAction;

希望这会有所帮助!