Created
August 5, 2017 02:10
-
-
Save sirgallifrey/04a35eec027a081729b833cbef002d81 to your computer and use it in GitHub Desktop.
is loged In HOC
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 Loader from '../components/loader'; | |
export default function fetchData(url, options) { | |
return (Component) => class fetchComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
finished = false; | |
data = null; | |
} | |
} | |
componentDidMount() { | |
fetch(url, options) | |
.then(r => r.json()) | |
.then(data => this.setState({ finished: true, data })) | |
} | |
render() { | |
return (this.state.finished ? <Component {...props} data={this.state.data}> : <Loading/>); | |
} | |
} | |
} | |
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 Auth from '../lib/auth'; | |
export function ifLoggedIn(Component) { | |
return (props) => ( | |
Auth.isLoggedIn ? <Component {...props}/> : null | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment