【问题标题】:React Native What is the fastest way of rendering view among using react state and redux state?React Native 使用 react state 和 redux state 渲染视图最快的方法是什么?
【发布时间】:2018-10-12 11:10:36
【问题描述】:

我在 iOS 和 Android 上使用过 react-native-maps,我也在地图上使用了很多标记。

所以我真的需要尽可能快地渲染视图。

在以下这些方式中,最快的方式是什么?

仅限 Redux

const mapStateToProps = (state) => ({
  a: state.a
});

render() {
  return (
    this.props.a ? (<View>isA</View>) : (<View>isNotA</View>)
  );
}

来自 Redux 的反应状态

state = { a: false }

static getDerivedStateFromProps(nextProps, prevState) {
  if (nextProps.a !== prevState.a) {
    return ({ a: nextProps.a })
  }
}

render() {
  return (
    this.state.a ? (<View>isA</View>) : (<View>isNotA</View>)
  );
}

【问题讨论】:

    标签: reactjs react-native redux


    【解决方案1】:

    我什至会在进入视图之前加载道具。假设您需要 B 页上的数据 要进入页面 B,您需要单击页面 A 上的按钮。

    当页面 A 被加载时,您请求页面 B 所需的数据。当导航到页面 B 时,您只需通过路由器传递属性,并且您可以从页面 B 组件中的开始使用它们。

    您对此有何看法?

    【讨论】:

    • 感谢您的回答。但我的意思是“在做不复杂的工作时是否存在速度上的差距,例如像传递prop(bool,string等)一样的东西?”
    • 不知道是不是只用上面的方式从父组件接收props时存在速度上的差距。
    • 您的评论不适合这个问题,但在其他用例中对我很有帮助。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2018-12-04
    • 2017-05-21
    • 2021-08-16
    • 2016-10-29
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多