I would like to know if there is a better way to conditionally pass a prop than using an if-statement.
For example, right now I have:
var parent = R
Actually, if your prop is boolean it isn't needed to implement condition but if you wanna add prop by inline condition you should write like below:
const { editable, editableOpts } = this.props;
return (
);
Hope it doesn't confuse you. the {...
means it is spread operator like passing existed props: {...props}
and the editable &&
means if editable
is true
the { editable: editableOpts }
object will make and with {...
we will make a new object like it: {...{ editable: editableOpts }}
that it means editable={editableOpts}
but if this.porps.editable
is true.