Last active
April 9, 2018 08:33
-
-
Save sergi/a7512836a9e0ff42f86a9ea68d731a67 to your computer and use it in GitHub Desktop.
Privileged Content article
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
<PrivilegedContent> | |
<span> | |
Privileged Content | |
</span> | |
</PrivilegedContent> |
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"; | |
class PrivilegedContent extends React.PureComponent { | |
state = { | |
admin: isAdmin() | |
}; | |
render() { | |
if (this.state.admin !== true) { | |
return <div />; | |
} | |
const { children, ...rest } = this.props; | |
React.Children.only(children); | |
const childrenWithProps = React.Children.map(children, child => | |
React.cloneElement(child, rest) | |
); | |
return {childrenWithProps}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment