# salps

> Simple and ligth persisted state

Latest version **0.0.7** (published 2020-07-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install salps
pnpm add salps
yarn add salps
bun add salps
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2020-07-06 |
| First published | 2020-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Thiago Bevenuto |
| Maintainers | tiorubs |

## Links

- npm: https://www.npmjs.com/package/salps
- npm.io page: https://npm.io/package/salps

## Recent versions

- 0.0.7 (latest) — 2020-07-06
- 0.0.6 — 2020-05-24
- 0.0.5 — 2020-05-24
- 0.0.4 — 2020-05-24
- 0.0.3 — 2020-05-24
- 0.0.2 — 2020-05-24
- 0.0.1 — 2020-05-24

## README

## SALPS

Simple and ligth persisted state (SALPS) is a lib for manager a local state in you app, with general purposes run with reactJS and react-native.

## Installation

Using npm:

```shell
npm install --save salps
```

or using yarn:

```shell
yarn add salps
```

## Usage

first create a store config file

```javascript
const initialState = {
  loged: false,
};

const config = { key: "ROOT", persistList: ["loged"] };

function reducers(state = initialState, action) {
  switch (action.type) {
    case "IN":
      return { ...state, loged: true };
    case "OUT":
      return { ...state, loged: false };
    default:
      return state;
  }
}

export default { initialState, config, reducers };
```

then insert your app inside of SALPSProvider

```javascript
import React from "react";
import { View, Text, Button } from "react-native";
import SALPS, { useSALPS } from "salps/native";
import storeConfig from "./store";

export default function Navigator() {
  return (
    <SALPS {...storeConfig}>
      <App />
    </SALPS>
  );
}

function App() {
  const { state } = useSALPS();
  return state.loged ? <Dashboard /> : <Auth />;
}

function Auth() {
  const { dispatch, state } = useSALPS();

  function login() {
    dispatch({ type: "IN" });
  }

  return (
    <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
      <Text>Auth</Text>
      <Button title="Login" onPress={login} />
    </View>
  );
}

function Dashboard() {
  const { dispatch } = useSALPS();

  function logout() {
    dispatch({ type: "OUT" });
  }

  return (
    <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
      <Text>Dashboard</Text>
      <Button title="Logout" onPress={logout} />
    </View>
  );
}
```

## useSALPS();

using the hook useSALPS you can acess :

loading // true until the storage load

state // all state

dispatch // function to dispatch actions to change state

## TODO

> better readme
> to TypeScript

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