我正在尝试增量和减量教程。当我在textinput上输入数字时,此值将反映到给定的此文本中。但是我遇到了错误。错误提示
undefined is not a function(evaluating 'this.props.counterSet(count)')
这些是我尝试过的代码。谁能告诉我我在哪里做错了。
谢谢
- App
-Actions
-ActionTypes.js
-CounterAction.js
-Reducers
-counterReducer.js
app.js
export default (state = 0, action) => {
switch (action.type) {
case 'SET':
return action.payload;
default:
return state;
}
}
export const counterSet = (receivedNumber) => {
return {
type: 'SET',
payload: receivedNumber
}
}
export * from './CounterAction';
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);
答案 0 :(得分:1)
从
更改导入 export * from './CounterAction';
到
export { counterSet } from './CounterAction;
希望这会有所帮助!