# th12storage

> React State Manager

Latest version **1.0.2** (published 2022-02-15) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-02-15 |
| First published | 2022-02-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | th12legion |
| Maintainers | th12legion |
| Keywords | React, State, Manager, Global, js |

## Links

- npm: https://www.npmjs.com/package/th12storage
- Repository: https://github.com/th12legion/th12storage
- Homepage: https://github.com/th12legion/th12storage#readme
- Issues: https://github.com/th12legion/th12storage/issues
- npm.io page: https://npm.io/package/th12storage

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2022-02-15
- 1.0.1 — 2022-02-15
- 1.0.0 — 2022-02-14

## README

# th12storage

A small global state manager in React.

## How to use

```javascript
	import { useStorage } from "th12storage";

	function Test(){
		let [hello] = useStorage("hello", "Hello");
	}
```

To be able to change the value, you have to create a method to change it.

```javascript
	import { useStorage } from "th12storage";

	function Test(){
		let [hello, setHello] = useStorage("hello", "Hello", true);

		setHello("Hello, world!");
	}
```

But even with this change, the component will not respond to it. 
You need to create function trigger.

```javascript
	import { useState } from "react";
	import { useStorage } from "th12storage";

	function Test(){
		let [st, rst] = useState(0);
		let [hello, setHello] = useStorage("hello", "Hello", true);

		if(hello==="Hello"){
			setHello("Hello, world!", rst);
		}
	}
```

This method is not convenient if you use a lot of variables. In that case, you can use subscribes.

```javascript
	import { useState } from "react";
	import { useStorage, useStorageSubscribe } from "th12storage";

	function Test(){
		let [st, rst] = useState(0);
		useStorageSubscribe("Test", ["hello", "user"], rst);

		let [hello, setHello] = useStorage("hello", "Hello", true);
		let [user, setUser] = useStorage("user", "", true);

		if(user===""){
			setUser("John Doe");
		}else if(hello=="Hello"){
			setHello("Hello, "+user+"!");
		}
	}
```

## Parameters

useStorage(VARIABLE NAME, DEFAULT VALUE [,CREATE UPDATE VARIABLE TRIGGER])

useStorageSubscribe(COMPONENT NAME, SUBSCRIBES LIST, COMPONENT UPDATE TRIGGER)

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