Skip to content

Instantly share code, notes, and snippets.

@caub caub/Sux.js
Last active Jun 28, 2019

Embed
What would you like to do?
simple react state management
import React from 'react';
const SuxContext = React.createContext();
export class SuxProvider extends React.Component {
state = {};
render() {
return (
<SuxContext.Provider value={{...this.state, dispatch: data => this.setState(data)}}>
{this.props.children}
</SuxContext.Provider>
);
}
}
// usage <Sux>{({foo}) => <div>{foo}</div>}</Sux>
export default SuxContext.Consumer;
export const withSux = Component => props => (
<SuxContext.Consumer>
{data => <Component {...props} {...data} />}
</SuxContext.Consumer>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.