Can a react component have multiple areas for child content?
Make seperate components Donot use props to pass components as children. something like this.
header.js
import React from 'react';
import styles from "./index.css";
export default React.createClass({
getComponent(key) {
return this.props.children.filter( (comp) => {
return comp.key === key;
});
}
render: function() {
return (
<header className={styles.root}>
<div className={styles.logo}>
{this.getComponent('logo')}
</div>
<div>
{this.getComponent('navbar'}
</div>
</header>
);
}
});
app.js
export default React.createClass({
render: function() {
return (
<Header>
<Logo key="logo"/>
<Navbar key="navbar"/>
</Header>
);
}
});
import React, { Component } from 'react';
import styles from "./index.css";
import Logo from "./components/Logo";
import Navbar from "./components/Logo";
class Comp extends Component {
render(){
return (
<Header className={styles.root}
top={Logo}
right={Navbar}
/>
);
}
}
class Header extends Component {
render(){
let {top,right} =this.props;
return (
<header className={styles.root}>
<div className={styles.logo}>
{top && <top />}
</div>
<div>
{right && <right />}
</div>
</header>
);
}
}