【问题标题】:react native : There is way pass the "list" parameter to screen1 and screen2 without navigate to screen2反应原生:有办法将“列表”参数传递给 screen1 和 screen2 而无需导航到 screen2
【发布时间】:2020-08-27 08:44:42
【问题描述】:

可以将“list”参数传递给 screen1 和 screen2 而无需导航到 screen2

在我的示例中,我在导航到 screen1 时将参数数据“列表”移动到 screen1,我也想在 screen2 中使用此参数,该怎么做? 我需要使用钩子和导航 5。

onPress={() => {
              const fromDate = params.fromDate;
              const toDate = params.toDate;
              if (
                Array.isArray(listSelectedWaterSourceCode) === true &&
                listSelectedWaterSourceCode.length > 0
              ) {
                ListOfTheFlat(listSelectedWaterSourceCode, fromDate, toDate)
                  .then((list) => {
                    navigation.navigate('screen1', {
                      list,
                    });
                  })
                  .catch((error) => {
                    console.log(error);
                  });
              }
            }}

【问题讨论】:

    标签: javascript reactjs react-native react-hooks react-navigation


    【解决方案1】:

    是的你可以通过使用context API来实现这一点

    另一个解决方案是redux。你可以阅读他们的官方文档。

    【讨论】:

      猜你喜欢
      • 2020-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      相关资源
      最近更新 更多