Harshal Kalavadiya
Harshal Kalavadiya

Reputation: 2436

React native: how can i pass value in my custom component

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

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

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

Upvotes: 0

Views: 3345

Answers (1)

Yash Ojha
Yash Ojha

Reputation: 818

Its very simple You can access it by

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

Upvotes: 4

Related Questions