https://github.com/mcjazzyfunky/js-react-store
Very simple, small, non-magical store to be used in React
https://github.com/mcjazzyfunky/js-react-store
Last synced: 2 months ago
JSON representation
Very simple, small, non-magical store to be used in React
- Host: GitHub
- URL: https://github.com/mcjazzyfunky/js-react-store
- Owner: mcjazzyfunky
- License: lgpl-3.0
- Created: 2019-02-24T18:48:09.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-22T16:58:57.000Z (about 6 years ago)
- Last Synced: 2025-02-10T14:16:10.961Z (3 months ago)
- Language: TypeScript
- Size: 165 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# js-react-store
Very small store library to be used in React - mainly to be used locally within components
[](https://github.com/js-works/js-react-store/blob/master/LICENSE)
[](https://www.npmjs.com/package/js-react-store)
[](https://travis-ci.org/js-works/js-react-store)
[](https://coveralls.io/github/js-works/js-react-store?branch=master)## Installation
npm install --save js-react-store
## Usage
```tsx
import React from 'react'
import ReactDOM from 'react-dom'
import { initStore, useStore } from 'js-react-store'const { useCallback } = React
function createStore() {
const [self, update] = initStore({
count: initialValue,increment() {
increase(1)
},decrement() {
increase(-1)
}
})// private
function increase(delta: number) {
update(() => {
self.count += delta
})
}
return self
}function Counter() {
const
store = useStore(createStore),
increment = useCallback(() => store.increment(), []),
decrement = useCallback(() => store.decrement(), [])return (
Counter:
-
{` ${store.count} `}
+
)
}ReactDOM.render(, document.getElementById('main-content'))
```## License
"js-react-store" is licensed under LGPLv3.
## Project status
"js-react-store" is currently in alpha status.