Skip to content

Instantly share code, notes, and snippets.

@glortho
Last active July 6, 2017 19:31
Show Gist options
  • Save glortho/941d7ead6afe5f8e774c479e0fe5ac67 to your computer and use it in GitHub Desktop.
Save glortho/941d7ead6afe5f8e774c479e0fe5ac67 to your computer and use it in GitHub Desktop.
import React from 'react';
import { container, Children } from 'jetset';
@container({ active: false })
class Panels extends React.Component {
getActive = () => this.props.container.get().active;
setActive = selected => this.props.container.set({ active: selected });
render() {
return Children({
...this.props,
Panels: {
getActive: this.getActive,
setActive: this.setActive
}
});
}
}
class Panel extends React.Component {
render() {
const status = this.props.Panels.getActive();
return (
<div>
<span>Active panel is: { String( status ) }</span>
<button onClick={() => this.props.Panels.setActive( !status )}>Toggle active</button>
</div>
);
}
}
export default props => <Panels><Panel { ...props }/></Panels>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment