【发布时间】:2018-01-01 18:45:36
【问题描述】:
我希望我的应用程序使用 Redux 显示用户在其下的标签中输入的内容。
这是我的容器:
const mapStateToProps = state => ({
text: state
})
const mapDispatchToProps = (dispatch) => ({
addToList: () => { dispatch({ type: 'ADD_LIST' }) },
})
export default connect(mapStateToProps, mapDispatchToProps)(TodoList)
这是我的组件:
class TodoList extends Component {
render() {
return (
<View>
<TextInput
style={{height: 40, width: 300}}
placeholder="Type here to translate!"
onChangeText={(text) => this.props.text}
/>
<Button
title="Submit"
onPress={this.props.addToList}/>
<View>
<Text>{this.props.text}</Text>
</View>
</View>
)
}
}
export default TodoList;
这里是商店:
export const todoList = (state = [], action = {}) => {
switch (action.type) {
case 'ADD_LIST':
return [
...state,
action.todo
];
default:
return state;
}
}
let storeTodoList = createStore(todoList);
export default storeTodoList;
所以我正在尝试输入文本,将其添加到存储在商店中的列表中,然后显示它,但我完全不知道如何做到这一点......
【问题讨论】:
-
您在调用容器中的
dispatch时缺少有效负载 -
我不明白那里缺少什么。抱歉,从今天开始,我是 React Native 的初学者......
标签: android ios react-native redux react-redux