V
V
Vladimir Golub2019-03-25 17:57:50
React
Vladimir Golub, 2019-03-25 17:57:50

How to disable passing parameters to a component depending on conditions?

It is necessary to prohibit passing parameters to the component

<Component 
 {
  param == 'none' 
   ? 
   param1 = {this.props.param1}
   param2 = {this.props.param2}
   : null
 }
/>

I know that it is possible to forbid to transfer separately
But, what to do if there are a lot of parameters?
How to do something similar?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-03-25
@RazerVG

const { param1, param2 } = this.props;

const props = param === 'none' ? {} : { param1, param2 };

return (
  <Component {...props} />
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question