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
// A page component that just render text | |
const App = (props) => { | |
return ( | |
<div className="App"> | |
<h1>A component</h1> | |
</div> | |
); | |
}; | |
export default App; |
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
export const withUser = (Component) => (props) => { | |
// Passing the user that you fetched | |
const currentUser = { authtenticated: true, email: "[email protected]" }; | |
return <Component currentUser={currentUser} {...props} />; | |
}; |
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
// A page component that just render text | |
const App = (props) => { | |
return ( | |
<div className="App"> | |
<h1>A component</h1> | |
<h2>User: {props.currentUser.email}</h2> | |
</div> | |
); | |
}; | |
// Wrapping with withUser function |
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
export const withTitle = (Component) => (props) => { | |
const title = "Custom title"; | |
return <Component title={title} {...props} />; | |
}; |
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
const App = (props) => { | |
return ( | |
<div className="App"> | |
<h1>A component: {props.title}</h1> | |
<h2>User: {props.customUser.email}</h2> | |
</div> | |
); | |
}; | |
export default compose(withUser, withTitle)(App); |
OlderNewer