You can access the this.props.children
to make a layout kind of thing. You can access the child of some component inside itself by using this.props.children
.
class Div extends Component {
render() {
return <div {...this.props} >{this.props.children}</div>;
}
}
This will wrap anything you put inside the Div
tag between the HTML div tag. To access the props of the component given to the <Div>
, you can simply add {...this.props}
, it will add all your props on the actual div
.
You can use the above-given component like:
<Div className="custom" custom_prop="value"><AnyReactComponent /></Div>
will convert to:
<div className="custom" custom_prop="value"><AnyReactComponent /></div>