React props: Should I pass the object or its properties? Does it make much difference?

According to the principle of least privilege, this is a correct way: <InnerComponent name={object.name} image={object.image} /> This restricts InnerComponent from accidentally modifying original object or accessing properties that aren’t intended for it. Alternatively, properties could be picked from original object and passed as props: <InnerComponent {…pick(object, ‘name’, ‘image’)} /> If there are numerous properties that … Read more

Passing object as props to jsx

Is this possible? Yes its possible, but the way you are sending it is not correct. The meaning of <MyJsx commonProps /> is: <MyJsx commonProps={true} /> So if you don’t specify any value, by default it will take true. To pass the object, you need to write it like this: const commonProps = {myProp1: ‘prop1’,myProp2: … Read more

forEach() in React JSX does not output any HTML

You need to pass an array of element to jsx. The problem is that forEach does not return anything (i.e it returns undefined). So it’s better to use map because map returns an array: class QuestionSet extends Component { render(){ <div className=”container”> <h1>{this.props.question.text}</h1> {this.props.question.answers.map((answer, i) => { console.log(“Entered”); // Return the element. Also pass key … Read more