# @chchang810716/react-sss

> another react state management solution

Latest version **1.2.2** (published 2021-01-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @chchang810716/react-sss
pnpm add @chchang810716/react-sss
yarn add @chchang810716/react-sss
bun add @chchang810716/react-sss
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2021-01-02 |
| First published | 2021-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 18.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | CHChang810716 |
| Maintainers | chchang810716 |

## Links

- npm: https://www.npmjs.com/package/@chchang810716/react-sss
- Repository: https://github.com/CHChang810716/react-sss
- Homepage: https://github.com/CHChang810716/react-sss#readme
- Issues: https://github.com/CHChang810716/react-sss/issues
- npm.io page: https://npm.io/package/@chchang810716/react-sss

## Recent versions

- 1.2.2 (latest) — 2021-01-02
- 1.2.1 — 2021-01-02
- 1.2.0 — 2021-01-02
- 1.1.0 — 2021-01-02
- 1.0.0 — 2021-01-02

## README

# react-sss (react simple shared state)

Yet, another react function component shared state management solution.

[![NPM](https://img.shields.io/npm/v/react-sss.svg)](https://www.npmjs.com/package/react-sss) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save react-sss
```

## Usage

```jsx
import React from 'react'
import { useState, State } from 'react-sss'

// create state(data model)
const todos = new State([]);
const done = new State([]);
const editingTodo = new State("");

const NewTodo = () => {
  const text = useState(editingTodo)
  const todoList = useState(todos)
  return (<div>
    <input type="text" value={text} onChange={
      e => editingTodo.set(e.target.value)
    }/>
    <button onClick={e => {
      // add edited todo to todo list
      todos.set([text, ...todoList])
      // clean editing todo input 
      editingTodo.set('')
    }}>add</button>
  </div>)
}

const Item = ({tid, text}) => {
  const todoList = useState(todos)
  const doneList = useState(done)
  return <div>
    <button onClick={e => {
      // remove item from todo list
      const target = todoList[tid];
      let arr = [...todoList]
      arr.splice(tid, 1)
      todos.set(arr).then(()=>{
        // add removed item to done list
        return done.set([target, ...doneList])
      })
    }}>done</button>
    <button onClick={e => {
      // remove item from todo list
      let arr = [...todoList]
      arr.splice(tid, 1)
      todos.set(arr)
    }}>delete</button>
    <div style={{display: 'inline-block'}}>{text}</div>
  </div>
}

const App = () => {
  const todoList = useState(todos)
  const doneList = useState(done)
  return <div>
    <NewTodo />
    <div> TODO: </div>
    {
      todoList.map((text, i) => <Item key={i} tid={i} text={text}/>)
    }
    <div> DONE: </div>
    {
      doneList.map((text, i) => <div key={i}>{text}</div>)
    }
  </div>
}

export default App
```

## License

MIT © [CHChang810716](https://github.com/CHChang810716)

---
_Source: https://npm.io/package/@chchang810716/react-sss · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
