【问题标题】:Is there a way to pass data to other components in react-native-router-flux(Without access to Actions)有没有办法将数据传递给 react-native-router-flux 中的其他组件(无法访问操作)
【发布时间】:2021-04-29 12:03:02
【问题描述】:

我知道我可以这样做:

Actions.routeName(someDataObject)

如果我想在创建时向场景渲染的组件添加初始道具怎么办? 此时“操作”不可用?

【问题讨论】:

    标签: react-native react-native-router-flux


    【解决方案1】:

    啊,刚刚意识到传递给“场景”组件的任何道具都可以在该场景正在渲染的组件中使用。

    所以,像这样

               <Scene
                  key={route.key}
                  component={route.component}
                  initialProps={route.initialProps}
                  title={route.title}
                  hideNavBar={route.hideNavBar}
                  hideDrawerButton={false}
                  initial={route.initial}
                />
    

    意味着 initialProps 将在 'props.component' 中可用。

    【讨论】:

    • 我想我真正想要的是将数据作为道具传递给组件,这样数据在导航到另一个场景时会丢失。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 2020-11-24
    • 2017-07-04
    • 1970-01-01
    • 2018-08-25
    • 2019-12-06
    • 2017-12-03
    相关资源
    最近更新 更多