我什么时候真正需要 React Native 中的 Redux?

Lit*_*nny 2 state-management react-native redux

我开始学习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>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

den*_*emm 6

作为一个过于简单化的经验法则,我会说使用 Redux 存储来存储与不同不相关组件相关的数据,使用组件状态来存储在组件及其父级或子级之外没有任何意义的数据。

Redux 基本上是一个内存数据存储,如果您确实不需要,它会向您的应用程序添加大量样板代码。