Ошибка undefined не является функцией при изменении текста - PullRequest
0 голосов
/ 08 октября 2018

Я пытаюсь увеличить и уменьшить учебник.Когда я набираю число на вводе текста, это значение должно быть отражено в данном тексте.Но я получаю ошибку.Ошибка говорит

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 голосов
/ 08 октября 2018

Измените импорт с

export * from './CounterAction';

на

export { counterSet } from './CounterAction;

Надеюсь, это поможет!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...