gpt4 book ai didi

react-native - 如何覆盖功能组件中的导航选项?

转载 作者:行者123 更新时间:2023-12-03 15:25:04 24 4
gpt4 key购买 nike

要使用类组件覆盖导航选项,它将类似于

export default class SomeClass extends Component {

static navigationOptions = ({ navigation }) => {
return {
title: navigation.getParam('headerTitle'),
}
}

componentDidMount() {
this.props.navigation.setParams({ headerTitle: someVariableThatComesFromExternalCall })
}

...
}

但是我如何使用功能组件来做到这一点?
export default function SomeFunctionalCompoenent({ navigation }) {

// How and Where do I change the header title ?

useEffect(() => { navigation.setParams({ headerTitle: someVariableThatComesFromExternalCall })})
return (
...
)
}

最佳答案

您仍然需要在功能组件上定义 navigationOptions。你这样做:

export default function SomeFunctionalComponent({ navigation }) {
useEffect(() => {
navigation.setParams({
headerTitle: someVariableThatComesFromExternalCall
})
}, [])
}

SomeFunctionalComponent.navigationOptions = ({ navigation }) => {
return {
title: navigation.getParam('headerTitle'),
}
}

关于react-native - 如何覆盖功能组件中的导航选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55505026/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com