React native:我如何在自定义组件中传递值

时间:2022-08-22 20:21:52

i want to pass my params value in my custom component so below is my code

我想在我的自定义组件中传递我的params值,所以下面是我的代码

Header.js

Header.js

class Header extends Component {

constructor(props) {
    super(props);
}


render() {
    return (
        <View >
        <Text >Title</Text>
        <Text>subtitle</Text>
        </View>
    );
   }

 }

I call my Header.js from my main.js

我从main.js调用了我的Header.js

class Main extends Component {

constructor(props) {
    super(props);
}


render() {
    return (
        <Header title = {this.props.navigation.state.params.screen_title} subtitle= {this.props.navigation.state.params.subtitle} />
    );
    }

 }

I pass my title and subtitle in my header component , i just wanted to know how can i access my passing variable value in my header component ? your all suggestions are appreciable

我在标题组件中传递了标题和副标题,我只是想知道如何在标题组件中访问传递变量值?你的所有建议都很明显

1 个解决方案

#1


3  

Its very simple You can access it by

它非常简单你可以访问它

this.props.title
this.props.subTitle
this.props.nameOfTheProps

#1


3  

Its very simple You can access it by

它非常简单你可以访问它

this.props.title
this.props.subTitle
this.props.nameOfTheProps