# @yogjin/react-global-state

> Simple global state management library for react18

Latest version **0.0.3** (published 2023-08-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @yogjin/react-global-state
pnpm add @yogjin/react-global-state
yarn add @yogjin/react-global-state
bun add @yogjin/react-global-state
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2023-08-25 |
| First published | 2023-08-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Youngjin Park |
| Maintainers | yogjin |
| Keywords | react, state, global state, useSyncExternalStore |

## Links

- npm: https://www.npmjs.com/package/@yogjin/react-global-state
- Repository: https://github.com/yogjin/react-global-state
- Homepage: https://github.com/yogjin/react-global-state#readme
- Issues: https://github.com/yogjin/react-global-state/issues
- npm.io page: https://npm.io/package/@yogjin/react-global-state

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^18.2.0
- [react-dom](https://npm.io/package/react-dom.md) ^18.2.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2023-08-25
- 0.0.2 — 2023-08-24

## README

# React-global-state  &middot; [![NPM Version](https://img.shields.io/npm/v/@yogjin/react-global-state)](https://www.npmjs.com/package/@yogjin/react-global-state) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/yogjin/react-global-state/blob/main/LICENSE)
`react-global-state` is simple global state management library for React 18.

## Installation
The Recoil package lives in [npm](https://www.npmjs.com/package/@yogjin/react-global-state)

To install the latest stable version, run the following command:
```sh
npm i @yogjin/react-global-state
```
Or if you're using [yarn](https://yarnpkg.com/getting-started/usage):
```sh
yarn add @yogjin/react-global-state
```

## How to use
Fundamentally, it's very similar to the concept of Recoil. 

`globalState` is similar to `atom` 

`useGlobalState` is similar to `useRecoilState`

### Make `globalState`

```tsx
import { globalState } from '@yogjin/react-global-state';

export const countState = globalState([1]);
```

### Use `useGlobalState`

#### React Component

```tsx
import { countState } from './globalStates';
import { useGlobalState } from '@yogjin/react-global-state';

export default function Component() {
  const [counts, setCounts] = useGlobalState(countState);
  ...
}
```
#### Non-React Code
Even outside of React components, you can use useSetGlobalState to set the globalState. 

Likewise, if there's a change in the state, any component subscribed to that globalState will be re-rendered.

```ts
import { countState } from "./globalStates";
import { useSetGlobalState } from '@yogjin/react-global-state';

const setCountState = useSetGlobalState(countState);

const add100ToCountState = () => {
    setCountState((prevCount) => [...prevCount, 100]);
}
```

### License
`react-global-state` is [MIT licensed](https://github.com/yogjin/react-global-state/blob/main/LICENSE)https://github.com/yogjin/react-global-state/blob/main/LICENSE.

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