Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-global-state

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-global-state

An elegant state management solution for React. The philosophy of this project is to keep the core simple and scalable by exposing low-level accessibility and middleware composition, not by adding options. All the non-core functions are just examples of h

  • 0.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Overview

An elegant state management solution for React. The philosophy of this project is to keep the core simple and scalable by exposing low-level accessibility and middleware composition, not by adding options. All the non-core functions are just examples of how you can compose functions to achieve common features.

Features

  • Non-opinionated: Like useState, only one core function, others are built on top of it.
  • Type safe: The state is type safe and the return value is intuitive.
  • Global: The state is global, you can access it anywhere.
  • Scalable: Naturally scale large state into multiple modules and files without performance degradation.
  • Middlewares: Simple and type-safe middleware composition interface.
  • Tiny: About 0.3KB Minified + Gzipped.

Documentation

Get started

npm install create-global-state
import create from "create-global-state";

const [useCount, setCount] = create(0);

const inc = () => setCount((c) => c + 1);

export default function App() {
  return <button onClick={inc}>Count {useCount()}</button>;
}

Examples

Check the Counter for basic usage, or try it online.

Check the CounterPersistent, MonolithStore, TodoApp for more advanced usage.

FAQ

Why not use react-use's createGlobalState?

Its implementation is not type safe and the return value is not intuitive. It's too late to make a PR to change its interface.

Why not zustand?

The typescript support is not good enough, the API is not intuitive. create-global-state is more like useState which aligns with the react API style. Check the comparison. Zustand Slices Pattern can cause naming conflict issues. create-global-state can naturally scale states by modules and files. The setter of zustand must be called within a react component, while the setter of create-global-state can be called anywhere.

FAQs

Package last updated on 18 Oct 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc