Answer the question
In order to leave comments, you need to log in
How to conditionally pass a parameter to a component in React?
How to conditionally pass a parameter to a component in React? I thought that something like this could turn out, but this code crashes with an error:
<Page title="SOME TEXT" {this.state.content === null ? "no_text" : null}>
<Page title="SOME TEXT" no_text>
<Page title="SOME TEXT">
Answer the question
In order to leave comments, you need to log in
<Page title="SOME TEXT" no_text={this.state.content === null}>
<Page title="SOME TEXT" {...(this.state.content === null?{no_text:true}:{})}>
As I understand it, no_text is a boolean parameter (true or false).
You can do it like this: !!value - casts value to a boolean value:
<Page title='...' no_text={!!this.state.content}>
!!null === false
!!'' === false
!![] === true
!!'aaa' === true
<Page /> или <Page></Page>, а у вас <Page>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question