【发布时间】:2018-05-30 22:49:34
【问题描述】:
我开始学习 react-native 和 redux。在某些领域,由于复杂性,我可以在某些组件中使用 redux,而某些组件仅通过 setState 和组件中的 this.state 在 react-native 中使用本地状态。
import React, { Component } from 'react';
import { AppRegistry, Text, View } from 'react-native';
class Blink extends Component {
constructor(props) {
super(props);
this.state = {isShowingText: true};
// Toggle the state every second
setInterval(() => {
this.setState(previousState => {
return { isShowingText: !previousState.isShowingText };
});
}, 1000);
}
render() {
let display = this.state.isShowingText ? this.props.text : ' ';
return (
<Text>{display}</Text>
);
}
}
【问题讨论】:
-
当您至少有一个组件管理自己的状态而不是通过调度程序发出操作时,Redux 不再按预期工作
标签: react-native redux state-management