react navigation - prop值被用作导航setOption:参数键



有可能这样做吗?

const MyComponent = (position) => {
useLayoutEffect(() => {
navigation.setOptions({
position: () => <CustomComponent />
});
}, [navigation, position]);
...
};

所以传递给MyComponent的position值要么是'headerLeft'要么是'headerRight'

假设position是包含'headerLeft''headerRight'的字符串,您可以创建对象并将其传入:

useLayoutEffect(() => {
let opts = { };
opts[position] = () => <CustomComponent />;
navigation.setOptions(opts);
}, [ navigation, position ]);

最新更新