gpt4 book ai didi

react-native - react 导航 5.0 标题按钮

转载 作者:行者123 更新时间:2023-12-03 23:27:40 26 4
gpt4 key购买 nike

我试图直接从组件添加右侧导航标题按钮,并且实现步骤已更改导航 5.0 版本,有一种方法提供添加按钮的方法

function HomeScreen({ navigation }) {
const [count, setCount] = React.useState(0);

navigation.setOptions({
headerRight: () => (
<Button onPress={() => setCount(c => c + 1)} title="Update count" />
),
});

return <Text>Count: {count}</Text>;
}

但需要对其实现
export default class HomeScreen extends Component {


constructor() {
super()

}
render() {
return ()
}
}

最佳答案

您可以在组件构造函数中执行此操作

this.props.navigation.setOptions({
headerRight: () => <Button />
});

关于react-native - react 导航 5.0 标题按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60225828/

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