Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Conditionally pass props to react component

var condition = true;

var props = {
  value: 'foo',
  ...(condition && { disabled: true })
};

var component = <div {...props} />;

// Or

var condition = true;

var component = (
  <div value="foo" {...(condition && { disabled: true })} /> 
);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Conditionally #pass #props #react #component
ADD COMMENT
Topic
Name
1+8 =