10
I created a project to study React and I’m trying to uncouple my Header from the app by creating a component for it. I created a file Header.jsx
and passed the code there but I’m getting the following error:
Failed propType: Invalid prop
children
supplied toRouter
. Check the render method ofHeader
.
Header.jsx
import React, { Component, PropTypes } from 'react';
import Link from 'react-router';
import { Header as HeaderMDL, Drawer, Navigation } from 'react-mdl';
const activeClassName = 'active';
class Header extends Component{
render() {
<div>
<Header title="React SaaS" scroll>
<Navigation>
<Link activeClassName={activeClassName} to="/home">Home</Link>
<Link activeClassName={activeClassName} to="/login">Login</Link>
</Navigation>
</Header>
<Drawer title="React SaaS">
<Navigation>
<Link to="/home">Home</Link>
<Link to="/login">Login</Link>
</Navigation>
</Drawer>
</div>
}
};
Header.propTypes = {
children: PropTypes.oneOfType([
PropTypes.element,
PropTypes.arrayOf(PropTypes.element),
]),
};
export default Header;
app.jsx
import React from 'react';
import ReactDOM from 'react-dom'
import Router from 'react-router';
import { IndexRoute, Link, Route } from 'react-router';
import ReactMDL from 'react-mdl';
import { Layout , Header as HeaderMDL, Drawer, Navigation } from 'react-mdl';
import Header from './components/Header.jsx';
import Login from './components/Login.jsx';
import Home from './components/Home.jsx';
class App extends React.Component{
render() {
return (
<div className="big-content" style={{height: '300px', position: 'relative'}}>
<Layout>
<Header />
<div className="wrapper">
{this.props.children}
</div>
</Layout>
</div>
) ;
}
};
let routes = (
<Route path="/" component={App}>
<Route path="home" component={Home}/>
<Route path="login" component={Login}/>
</Route>
);
ReactDOM.render(<Router>{routes}</Router>, document.getElementById('app'))
Any idea what’s going on?
Managed to solve
– durtto
The problem hasn’t been solved yet. For system needs I needed to change this whole component and it ended up working, but I’ll leave the question open so that, if anyone knows the answer to this specific case, your solution helps the community.
– jpklzm
It seems that your Component Header has render but there is no Return() inside the render.. the render must have a Return
– Guilherme Louro
True @Guilhermelouro, hadn’t noticed this at the time.
– jpklzm