Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created April 2, 2020 03:13
Show Gist options
  • Save jsmanifest/59a9bb775551ca01882157bdf3a22dd4 to your computer and use it in GitHub Desktop.
Save jsmanifest/59a9bb775551ca01882157bdf3a22dd4 to your computer and use it in GitHub Desktop.
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