¿Es posible algo de la siguiente manera:
const MyComponent = (position) => { useLayoutEffect(() => { navigation.setOptions({ position: () => <CustomComponent /> }); }, [navigation, position]); ... }; Entonces, el valor de position que se pasa a MyComponent será: 'headerLeft' o 'headerRight'
Suponiendo que position es una cadena que contiene 'headerLeft' o 'headerRight' , podría crear el objeto y pasarlo:
useLayoutEffect(() => { let opts = { }; opts[position] = () => <CustomComponent />; navigation.setOptions(opts); }, [ navigation, position ]);