是否可以传递给navigation.setParams(带有参数的函数)?

时间:2020-04-06 16:43:10

标签: react-native react-navigation

你好,我有一个函数,我想移到一个单独的模块,然后将其导入并用navigation.setParams进行引用,以便使用标题中的图标进行调用。问题是我必须传递一些参数。可以使用navigation.setParams完成此操作,还是有另一种方法?


  const useTimerFunc = (setModalVisible, setModalChoice, setGamesStatus) => {
      ....
      if (true) {
        setModalVisible(true);
        setModalChoice("A_Game_Is_On");
        setGamesStatus(...)
      } else {
        setModalChoice("No_Started_Game_Yet");
        setModalVisible(true);
      }
  };

// Previously it didn't need any parameters and this would work.
  useEffect(() => {
    props.navigation.setParams({ useTimerFunc });
  }, []);

...

CategoriesScreen.navigationOptions = ({ navigation }) => {
  const useTimerFunc = navigation.getParam("useTimerFunc");
... 
// So I can trigger it from here using HeaderButtons and an icon.

谢谢!

0 个答案:

没有答案
相关问题