React Component wait for required props to render

前端 未结 1 721
旧巷少年郎
旧巷少年郎 2021-02-09 00:36

I am declaring a component inside of a parent component. I want to establish specific props in one file, and then in the parent component, I want to be able to establish the oth

相关标签:
1条回答
  • 2021-02-09 01:25

    You can use a conditional render statement to only render the child when the props are populated:

    let {foo, bar} = this.props;
    
    <ParentComponent>
        { foo && bar ? <ChildComponent foo={foo} bar={bar} /> : null }
    </ParentComponent>
    

    Or instead of null you could render a <LoadingSpinner /> or something.

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