Answer the question
In order to leave comments, you need to log in
How to pass only valid props to a React component?
For example, there is a component:
const { title, description } = this.state
<NewsComponent
title,
description
/>
description
, only if it exists, i.e. not undefined
? NewsComponent
it already do a check on what exists and what does not?
Answer the question
In order to leave comments, you need to log in
There are many ways
to do this in a simple way, through the spread operator
const { ...rest } = this.state
<NewsComponent
{ ...rest }
/>
const { title, description = "" } = this.state
<NewsComponent
title,
description
/>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question