Skip to content

Instantly share code, notes, and snippets.

@raghavgarg1257
Last active July 1, 2018 11:05
Show Gist options
  • Save raghavgarg1257/1ad1eb6a8b61c97e6f107c8c2917fff1 to your computer and use it in GitHub Desktop.
Save raghavgarg1257/1ad1eb6a8b61c97e6f107c8c2917fff1 to your computer and use it in GitHub Desktop.
Consider the use of `children` for wrapping everything in one component. Its very common to use this `children` prop.
import React, { Component } from 'react';
import { Route, Switch } from 'react-router-dom'
// import pages
import Container from './Container';
import Greetings from './Greetings';
import Customers from './Customers';
class App extends Component {
render() {
return (
<Switch>
<Container>
<Route exact path="/" component={ Greetings }></Route>
<Route path="/customers" component={ Customers }></Route>
</Container>
</Switch>
);
}
}
export default App;
import React, { Component } from 'react';
export default function Container({ props }) {
return (
<div className="wrapper-class">
{ props.children }
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment