Created
October 16, 2020 14:26
-
-
Save RenatoSiqueira/f24caaa12547badecc619f6724ec307d to your computer and use it in GitHub Desktop.
Aluno Breno Cristovao - Exemplo de Prop Drilling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; | |
const ListRevenda = (props) => { | |
console.log('ListRevenda Props: ', props) | |
return ( | |
<div> | |
ListRevenda | |
<pre> | |
{ | |
JSON.stringify(props, null, 2) | |
} | |
</pre> | |
</div> | |
) | |
} | |
export const PrivateRoute = ({ component: Component, roles , ...rest }) => { | |
console.log('PrivateRoute Roles: ', roles) | |
return ( | |
<Route {...rest} render={props => { | |
const currentUser = 'MOCK: authenticationService.currentUserValue'; | |
if (!currentUser) { | |
return "MOCK: Redireciona pro login" | |
} | |
// AQUI: | |
return <Component {...props} roles={roles} /> | |
}} /> | |
) | |
} | |
function App() { | |
return ( | |
<Router> | |
<div className="wrapper"> | |
<div id="content"> | |
<div className="container-fluid"> | |
<section name='content'> | |
<Switch> | |
<PrivateRoute path='/revenda' exact component={ListRevenda} roles={"[_LevelRoles.UsrRevenda]"} /> | |
</Switch> | |
</section> | |
</div> | |
</div> | |
</div> | |
</Router> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment