Created
February 14, 2018 22:43
-
-
Save keidrun/081c521b9e7b2afb21f17207738f3a6d to your computer and use it in GitHub Desktop.
React HOC examples
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'; | |
const Auth = props => { | |
const password = 'anyPassword'; | |
if (password != 'correctPassword') { | |
return <h3>You are not authorized</h3>; | |
} else { | |
return props.children; | |
} | |
}; | |
export default Auth; |
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'; | |
const userHoc = (WrappedComponent, arg1) => { | |
return props => ( | |
<div> | |
{arg1} | |
<WrappedComponent {...props} /> | |
</div> | |
); | |
}; | |
export default userHoc; |
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 '../hoc/auth'; | |
const Page = props => { | |
return ( | |
<div> | |
<Auth> | |
<SecretPage>Home</SecretPage> | |
</Auth> | |
</div> | |
); | |
}; | |
export default Page; |
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 userHoc from '../hoc/userHoc'; | |
const User = props => { | |
return <div>User</div>; | |
}; | |
export default userHoc(User, 'Hello'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment