Socket
Book a DemoInstallSign in
Socket

zustand-divisions

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zustand-divisions

Zustand Divisions is a modular state management extension for Zustand, enabling a division-based approach for greater flexibility, especially in large state structures.

0.1.12
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
0
Weekly downloads
 
Created
Source

Zustand Divisions

Zustand Divisions is a modular state management extension for Zustand, enabling a division-based approach for greater flexibility, especially in large state structures.

Installation

npm install zustand-divisions

Usage Example

import { create } from 'zustand';
import { createDivision, divide, divisionHook } from 'zustand-divisions';

const division1 = createDivision(() => ({
  prefix: 'division1',
  creator: () => ({ dataInDivision1: 'data' }),
}));

const division2 = createDivision(() => ({
  prefix: 'division2',
  creator: () => ({ dataInDivision2: 'data' }),
}));

const useStore = create(
  divide([division1(), division2()], () => ({ mainData: 'data' }))
);
export const useDivision1 = divisionHook(useStore, division1());
export const useDivision2 = divisionHook(useStore, division2());

TypeScript Support

Zustand Divisions is fully typed for better state safety. See the examples for TypeScript implementations.

Middleware Compatibility

Integrates seamlessly with Zustand middleware. See the example for usage.

Additional Examples

More examples can be found in the examples directory, covering various use cases including third-party libraries.

Key Utilities

  • createDivision: Creates a new state division.
  • divide: Combines divisions into a single store.
  • divisionHook: Generates hooks for accessing division states.
  • divisionHooks: Creates hooks for multiple divisions.
  • spreadDivisions: Merges division data into a parent state.
  • stateToDivision: Extracts a division's state from the parent state.
  • divisionToState: Converts division state to parent state.
  • partializeDivision: Creates a partialized version of a division’s state.
  • partializeDivisions: Partializes multiple divisions at once.

For full documentation, visit the repository.

Keywords

react

FAQs

Package last updated on 08 Feb 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.