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

shapesjs-gsm

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shapesjs-gsm

A primitive state management for React

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
0
Weekly downloads
 
Created
Source

Shapes.js Global State Management

This project takes the idea of Recoil.js(no longer maintained) and Jotai but simplifies it moreso to avoid any dependencies within React other than React itself. This means the project is very small, and be tree-shaken and do not require any Context providers to work.

Installation

Install by running

yarn i shapesjs-gsm

Features:

Use anywhere 🌎

Because this library does not require any Context providers, you can simply install the library and create states anywhere. You can even read and write values without the need for hooks.

Within components
// Exported from another file to enable HMR.
export const nameShape = shape('');

// Main app
export function App() {
  const [name, setName] = useShape(nameShape);

  return (
    <>
      <input
        value={name}
        onChange={({ currentTarget: { value } }) => setName(value)}
      />
      My name is {name}
    </>
  );
}
Within helper functions
export const updateName = (name: string) => nameShape.setValue(name);

Familiar syntax 💪

The library uses very similar syntax to React.useState so it's super easy to pick up.

A simple example:

// Exported from another file to enable HMR.
export const buttonCount = shape(0);

// Main app
export function App() {
  const [count, setCount] = useShape(buttonCount);

  const increment = () => setCount((i) => i + 1);

  return <button onClick={increment}>Button has been click {count} times</button>;
}

State Persistance through Storage 📦

Support for any Storage class to manage a persistant state of any shape.

You can modify the above to use localStorage to maintain the shape's value on page navigation.

export const buttonCount = shape(0, window.localStorage);

You can use any custom storage class usage which implements setItem and getItem interfaces.

Typescript support ✅

Typed for convenience.

HMR ♻️

The library supports hot module reloading and maintains the values of the "shapes" (states) between HMR re-renders during development.

FAQs

Package last updated on 16 Jul 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