title: How to pass props conditionally to a component in React JS
body: <p>I have a component called &quot;Switch&quot;, it takes a few parameters such as label, name, onChange, selected etc..</p>
  <p>Now, in my scenario I'm calling an API and getting response. In JSON response, I have value of a field as &quot;Yes&quot; or &quot;No&quot;.</p>
  <p>I need to pass &quot;switched&quot; to the component if the value is &quot;Yes&quot;, otherwise do not pass anything.</p>
  <pre><code>          &lt;Switch
              label={field.label}
              name={field.fieldID}
              disabled={field.disabled}
              onChange={this.getNextFields}
              checked
            &gt;
              {field.control.modes[0].options.map((option, index) =&gt; {
                return (
                  
                    &lt;Strong&gt;{option.key}&lt;/Strong&gt;
                  
                );
              })}
            &lt;/Switch&gt;
  </code></pre>
  <p>How do I pass it? I'm trying to use ternary operator. But no luck. Your help would be much appreciated.</p>