react-native - 我什么时候真正需要在 React Native 中使用 redux?

标签 react-native redux state-management

我开始学习 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 存储与不同的不相关组件相关的数据,使用组件状态存储在组件及其父或子组件之外没有意义的数据。

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

关于react-native - 我什么时候真正需要在 React Native 中使用 redux?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50614337/

相关文章:

reactjs - 使用 axios 收到 400 错误错误请求

javascript - react native + redux-persist : how to ignore keys (blacklist)?

react-native - react native 相机胶卷

reactjs - 控制台记录导入的 SVG 给出数字

javascript - redux 中的嵌套智能组件

firebase - 如何为提供者设置登录屏幕过渡的动画?

asp.net - 用户组的 session 超时不同

flutter - 在 Flutter 中使用 Clean Architecture 在哪里执行状态更改?

javascript - 如何在 switch 语句(redux reducer)中更改数组的 ID?

ios - 在 ios react-native 中打开应用程序设置