Passing Props to Screens in React Native

前端 未结 2 2002
借酒劲吻你
借酒劲吻你 2021-01-28 02:03

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

相关标签:
2条回答
  • 2021-01-28 02:37

    In the constructor of HomeScreen, props should be able to passed to BaseComponent through

    constructor(props) {
      super(props);
    ...
    

    does it work for you?

    0 讨论(0)
  • 2021-01-28 02:51
    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.

    0 讨论(0)
提交回复
热议问题