Created
April 2, 2020 03:13
-
-
Save jsmanifest/59a9bb775551ca01882157bdf3a22dd4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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' | |
function isAuthed(token) { | |
// some auth logic | |
} | |
const withAuthValidation = (WrappedComponent) => { | |
return (props) => { | |
if (isAuthed(props.token)) { | |
return <WrappedComponent {...props} /> | |
} | |
return <WrappedComponent {...props} disabled /> | |
} | |
} | |
const DeactivatorInput = ({ style, ...rest }) => ( | |
<input | |
{...rest} | |
style={{ | |
minWidth: 200, | |
border: '1px solid rgba(0, 0, 0, 0.5)', | |
borderRadius: 4, | |
padding: '6px 12px', | |
...style, | |
}} | |
placeholder="Search a user to deactivate" | |
/> | |
) | |
// Applies the higher order component. This is the component we use to render | |
// in place of DeactivatorInput | |
const DeactivatorInputWithAuthValidation = withAuthValidation(DeactivatorInput) | |
function App() { | |
return ( | |
<div> | |
<DeactivatorInputWithAuthValidation /> | |
</div> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment