Root component as React.component

6.5k views Asked by At

I'm using react-boilerplate and I'm trying to change the App component to extend React.Component, since I'm trying to implement authentication and displaying/showing side menu depending on authentication state by following this example. As you can see, originally props are passed to App via props parameter. I've changed the App/index.js class to this:

import React from 'react';
import Header from 'components/Header';
import SideMenu from 'containers/SideMenu';
import Footer from 'components/Footer';
import auth from 'utils/auth'

export class App extends React.Component {
  render() {
  console.log(props)
  return (
      <div>
        <Header />
        <SideMenu />
        {React.Children.toArray(props.children)}
        <Footer />
      </div>
    );
  }
}

App.propTypes = {
  children: React.PropTypes.node,
};

export default App;

This throws an error that props are not defined:

ReferenceError: props is not defined App.render **/App/index.js

You can see how root route is instantiated here:

// Set up the router, wrapping all Routes in the App component
import App from 'containers/App';
import createRoutes from './routes';
const rootRoute = {
  component: App,
  childRoutes: createRoutes(store),
};

Any help would be appreciated.

1

There are 1 answers

3
Kinnza On BEST ANSWER

use:

this.props.children

Also you dont need to change the children to array

simply use:

 {this.props.children}