Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

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)