I have started to learn React Native and as always begin by creating reusable components. I learnt how you can pass and access props while creating custom components.
I
In the constructor of HomeScreen
, props should be able to passed to BaseComponent
through
constructor(props) {
super(props);
...
does it work for you?
class BaseComponent extends Component {
render() {
return (){
<Header title={this.props.title} />
}
}
}
class HomeScreen extends Component {
render() {
return (){
<BaseComponent title='this is your home screen' />
}
}
}
where Header
component is also a separate reusable component.
you need to pass props(in our case 'title') from the upper level component to base level components like the above example.