Answers for "react pass object as props"

7

pass props in react

/* PASSING THE PROPS to the 'Greeting' component */
const expression = 'Happy';
<Greeting statement='Hello' expression={expression}/> // statement and expression are the props (ie. arguments) we are passing to Greeting component

/* USING THE PROPS in the child component */
class Greeting extends Component {
  render() {
    return <h1>{this.props.statement} I am feeling {this.props.expression} today!</h1>;
  }
}
Posted by: Guest on May-29-2020
0

react pass object as props

Use the "spread" operator {... }

Usage: <MyJsx {...commonProps} />
Posted by: Guest on September-10-2021

Code answers related to "react pass object as props"

Code answers related to "Javascript"

Browse Popular Code Answers by Language