https://github.com/mattstypa/kedge
Easy to use global state hook for React.
https://github.com/mattstypa/kedge
Last synced: 3 months ago
JSON representation
Easy to use global state hook for React.
- Host: GitHub
- URL: https://github.com/mattstypa/kedge
- Owner: MattStypa
- License: mit
- Created: 2018-11-01T13:10:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T01:35:27.000Z (over 2 years ago)
- Last Synced: 2025-03-24T13:02:52.294Z (4 months ago)
- Language: JavaScript
- Size: 937 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Kedge
[](https://travis-ci.org/MattStypa/kedge)
[](https://www.npmjs.com/package/kedge)
[](https://www.npmjs.com/package/kedge)
[](https://www.npmjs.com/package/kedge)Easy to use global state hook for React.

[Read a little bit more here.](https://medium.com/@mattstypa/global-react-hook-usestate-86e6dd78a635)
## Installation
```
npm install kedge
```## Usage
```
import { createStore, useStore } from 'kedge';const priceStore = createStore();
function PriceComponent() {
const price = useStore(priceStore);
useEffect(fetchPrice, []);return (
Price: { price }
);
}function fetchPrice() {
priceStore.set(73);
}
```## API
- #### `const store = createStore(initialState, optionalName)`
Creates a `Store` with initial value. Optionally, it accepts a store name that is used in React Dev Tools- #### `const state = useStore(store)`
Returns current state from the `Store` and subscribes the component to it. If the `Store` changes state the component will re-render.- #### `Store.set(newState)`
Sets `Store` state and re-renders all components that use it.- #### `Store.reset()`
Sets `Store` to initial value and re-renders all components that use it.