An open API service indexing awesome lists of open source software.

https://github.com/timbroddin/react-global-state

🤗 Global state for your react-components.
https://github.com/timbroddin/react-global-state

Last synced: 8 months ago
JSON representation

🤗 Global state for your react-components.

Awesome Lists containing this project

README

          

# react-global-state

Sometimes you want global state in React, but you don't want the added complexity of using Redux. What if calling `setState` could update your entire state tree?

## Installation

`npm install --save react-global-state`

or

`yarn add react-global-state`

## Usage

Wrap your components with `gs`. Your global state will be available as the `state` and `setState` props.

import {gs} from 'react-global-state';

class Button extends Component {
onClick() {
const {state, setState} = this.props;
setState({counter: (state.counter) ? state.counter+1 : 1});
}

render() {
const {state} = this.props;
return

Click me

}
}

class Display extends Component {
render() {
const {state} = this.props;
return
Counter value: {state.counter}

}
}

const WrappedButton = gs(Button);
const WrappedDisplay = gs(Display);

class App extends Component {
render() {
const {state} = this.props;
return (




);
}
}

## Inspired by...

Redux, which I love and which you should use if your app has the least bit of complexity.