0

how to not to pass props base on condition? I can do this

const condition = true
<ThirdPartyComponent custom={() => condition ? <h1>hello<h1> : null}

but ThirdPartyComponent will still get null, I want to skip passing custom prop to ThirdPartyComponent. Note that I don't have access to ThirdPartyComponent.

  • Try using `undefined` instead of `null`. As per the answer here: https://stackoverflow.com/questions/32232659/react-inline-conditionally-pass-prop-to-component – Jayce444 Jun 28 '18 at 03:00

1 Answers1

2

Render component on basis of condition. Using ternary operator, if true then pass prop or don't pass it on else condition

You can do like this -

const condition = true;
condition ? (<ThirdPartyComponent custom={value} />) : (<ThirdPartyComponent /> )
Meet Zaveri
  • 2,921
  • 1
  • 22
  • 33