Socket
Book a DemoInstallSign in
Socket

@zoontek/react-global-state

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zoontek/react-global-state

[![bundlephobia](https://badgen.net/bundlephobia/minzip/@zoontek/react-global-state)](https://bundlephobia.com/result?p=@zoontek/react-global-state) [![npm version](https://badge.fury.io/js/%40zoontek%2Freact-global-state.svg)](https://www.npmjs.com/packa

latest
Source
npmnpm
Version
0.4.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@zoontek/react-global-state

bundlephobia npm version styled with prettier

Simple & minimalistic React global state management that works.

Installation

$ npm install --save @zoontek/react-global-state
# --- or ---
$ yarn add @zoontek/react-global-state

Motivation

TODO

Usage

// states/count.ts
import { createState, createHook } from "@zoontek/react-global-state";

const count = createState(0);

const {
  // State API
  addListener,
  getState,
  setState,
  resetState,
} = count;

export const useCount = createHook(count);

// You can derive values using the second argument
export const useCountPlusOne = createHook(count, (count) => count + 1);

export const decrement = () => setState((prevState) => prevState - 1);
export const increment = () => setState((prevState) => prevState + 1);
import { decrement, increment, useCount } from "./states/count.ts";

const Counter = () => {
  const count = useCount();

  return (
    <div>
      <span>count: {count}</span>

      <button onClick={decrement}>-1</button>
      <button onClick={increment}>+1</button>
    </div>
  );
};

Keywords

global

FAQs

Package last updated on 01 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts