Reactjs 导航道具对标题作出反应
如果有人创建了一个文件室,那么他将重定向到文件室,我将参数传递给它,如下所示:Reactjs 导航道具对标题作出反应,reactjs,react-native,react-navigation,Reactjs,React Native,React Navigation,如果有人创建了一个文件室,那么他将重定向到文件室,我将参数传递给它,如下所示: useEffect(() => { createdGroup === true ? navigation.navigate('Room', { roomIdent }) : null; }, [createdGroup]); 但我自定义了一个标题。如何将参数传递到标题 Stack.js ... <Stack.Screen name="Room"
useEffect(() => {
createdGroup === true ? navigation.navigate('Room', { roomIdent }) : null;
}, [createdGroup]);
但我自定义了一个标题。如何将参数传递到标题
Stack.js
...
<Stack.Screen
name="Room"
component={Room}
options={
{
headerTitle: () => <HeaderRoom />,
headerLeft: null,
headerStyle: {
elevation: 0,
borderBottomWidth: 0
}
}
}
/>
。。。
,
headerLeft:null,
头型:{
海拔:0,
边框宽度:0
}
}
}
/>
您需要提升状态。看看这个带有官方React文档的示例
class Calculator extends React.Component {
constructor(props) {
super(props);
this.handleCelsiusChange = this.handleCelsiusChange.bind(this);
this.handleFahrenheitChange = this.handleFahrenheitChange.bind(this);
this.state = {temperature: '', scale: 'c'}; }
handleCelsiusChange(temperature) {
this.setState({scale: 'c', temperature}); }
handleFahrenheitChange(temperature) {
this.setState({scale: 'f', temperature}); }
render() {
const scale = this.state.scale; const temperature = this.state.temperature; const celsius = scale === 'f' ? tryConvert(temperature, toCelsius) : temperature; const fahrenheit = scale === 'c' ? tryConvert(temperature, toFahrenheit) : temperature;
return (
<div>
<TemperatureInput
scale="c"
temperature={celsius} onTemperatureChange={this.handleCelsiusChange} /> <TemperatureInput
scale="f"
temperature={fahrenheit} onTemperatureChange={this.handleFahrenheitChange} /> <BoilingVerdict
celsius={parseFloat(celsius)} /> </div>
);
}
}
类计算器扩展React.Component{
建造师(道具){
超级(道具);
this.handleCelsiusChange=this.handleCelsiusChange.bind(this);
this.handleFahrenheitChange=this.handleFahrenheitChange.bind(this);
this.state={temperature:'',scale:'c'};}
handleCelsiusChange(温度){
this.setState({scale'c',temperature});}
handleFahrenheitChange(温度){
this.setState({scale:'f',temperature});}
render(){
恒温器刻度=this.state.scale;恒温器温度=this.state.temperature;恒温器摄氏度=刻度=='f'?温度转换(温度,托卡修斯):温度;恒温器华氏度=刻度=='c'?温度转换(温度,托法伦海):温度;
返回(
);
}
}
您可以在此处阅读更多内容:工作示例
像这样为房间设置堆栈。屏幕
<Stack.Screen
name="Room"
component={Room}
options={({ route }) => ({
headerTitle: () => <HeaderRoom Title={route.params.name} />,
headerLeft: null,
headerStyle: {
elevation: 0,
borderBottomWidth: 0,
},
})}
/>
import React from 'react';
import { Text } from 'react-native';
function HeaderRoom(props) {
console.log(props.Title) // it will log that custom title
return (
<Text style={{ fontWeight: 'bold', fontSize: 20 }}>{props.Title}</Text>
);
}
export default HeaderRoom;
你的
长什么样..给我们看看