Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oakfang/lensalot
Lens approach to global react state via Hooks
https://github.com/oakfang/lensalot
Last synced: 6 days ago
JSON representation
Lens approach to global react state via Hooks
- Host: GitHub
- URL: https://github.com/oakfang/lensalot
- Owner: oakfang
- License: mit
- Created: 2019-03-11T22:05:14.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T01:58:24.000Z (about 2 years ago)
- Last Synced: 2024-12-10T23:21:44.141Z (about 1 month ago)
- Language: JavaScript
- Size: 1.92 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 45
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lensalot
> Lens approach to global react state via Hooks
[![NPM](https://img.shields.io/npm/v/lensalot.svg)](https://www.npmjs.com/package/lensalot) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
## Install
```bash
npm install --save lensalot #or
yarn add lensalot
```## Usage
```jsx
import React from 'react';
import { LensProvider, useLens } from 'lensalot';const state = {
logic: {
foo: false,
count: 0,
},
};const Count = () => {
const [count] = useLens('logic.count');
return{count}
;
};const Increment = () => {
const [count, setCount] = useLens('logic.count');
return setCount(count + 1)}>+;
};const Toggle = () => {
const [foo, setFoo] = useLens('logic.foo');
return setFoo(!foo)}>{foo ? 'foo' : 'bar'};
};const Logic = () => {
const [logic] = useLens('logic');
return{JSON.stringify(logic)}
;
};function Root() {
return (
);
}
```## License
MIT © [oakfang](https://github.com/oakfang)