Skip to content

Instantly share code, notes, and snippets.

@sergi
Last active April 9, 2018 08:33
Show Gist options
  • Save sergi/a7512836a9e0ff42f86a9ea68d731a67 to your computer and use it in GitHub Desktop.
Save sergi/a7512836a9e0ff42f86a9ea68d731a67 to your computer and use it in GitHub Desktop.
Privileged Content article
<PrivilegedContent>
<span>
Privileged Content
</span>
</PrivilegedContent>
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