你好,我有一个函数,我想移到一个单独的模块,然后将其导入并用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.
谢谢!