All Projects → InfiniteXyy → zoov

InfiniteXyy / zoov

Licence: MIT License
Use 🐻 Zustand with Module-like api

Programming Languages

typescript
32286 projects
HTML
75241 projects

Projects that are alternatives of or similar to zoov

use-query-string
🆙 A React hook that serializes state into the URL query string
Stars: ✭ 50 (+108.33%)
Mutual labels:  hooks, state-management
micro-observables
A simple Observable library that can be used for easy state management in React applications.
Stars: ✭ 78 (+225%)
Mutual labels:  hooks, state-management
react-zeno
The React companion to Zeno, a Redux implementation optimized for Typescript.
Stars: ✭ 14 (-41.67%)
Mutual labels:  hooks, state-management
hooksy
Simple app state management based on react hooks
Stars: ✭ 58 (+141.67%)
Mutual labels:  hooks, state-management
react-smart-app
Preconfiguration React + Ant Design + State Management
Stars: ✭ 13 (-45.83%)
Mutual labels:  hooks, state-management
solid-zustand
🐻 State management in Solid using zustand.
Stars: ✭ 44 (+83.33%)
Mutual labels:  state-management, zustand
jedisdb
redis like key-value state management solution for React
Stars: ✭ 13 (-45.83%)
Mutual labels:  hooks, state-management
dobux
🍃 Lightweight responsive state management solution.
Stars: ✭ 75 (+212.5%)
Mutual labels:  hooks, state-management
preact-urql
Preact bindings for urql
Stars: ✭ 28 (+16.67%)
Mutual labels:  hooks, state-management
entangle
Global state management tool for react hooks inspired by RecoilJS and Jotai using proxies.
Stars: ✭ 26 (+8.33%)
Mutual labels:  hooks, state-management
resynced
An experimental hook that lets you have multiple components using multiple synced states using no context provider
Stars: ✭ 19 (-20.83%)
Mutual labels:  hooks, state-management
useStateMachine
The <1 kb state machine hook for React
Stars: ✭ 2,231 (+9195.83%)
Mutual labels:  hooks, state-management
react-cool-form
😎 📋 React hooks for forms state and validation, less code more performant.
Stars: ✭ 246 (+925%)
Mutual labels:  hooks, state-management
use-app-state
🌏 useAppState() hook. that global version of setState() built on Context.
Stars: ✭ 65 (+170.83%)
Mutual labels:  hooks, state-management
useSharedState
useSharedState is a simple hook that can be used to share state between multiple React components.
Stars: ✭ 0 (-100%)
Mutual labels:  hooks, state-management
stook
A minimalist design state management library for React.
Stars: ✭ 86 (+258.33%)
Mutual labels:  hooks, state-management
Reto
Flexible and efficient React Store with hooks.
Stars: ✭ 194 (+708.33%)
Mutual labels:  hooks, state-management
Reusable
Reusable is a library for state management using React hooks
Stars: ✭ 207 (+762.5%)
Mutual labels:  hooks, state-management
statery
Surprise-Free State Management! Designed for React with functional components, but can also be used with other frameworks (or no framework at all.)
Stars: ✭ 28 (+16.67%)
Mutual labels:  hooks, state-management
eventrix
Open-source, Predictable, Scaling JavaScript library for state managing and centralizing application global state. State manage system for react apps.
Stars: ✭ 35 (+45.83%)
Mutual labels:  hooks, state-management

ZOOV

ZOOV = Zustand + Module

Build Status Code Coverage npm-v npm-d brotli

Features

  • 😌 Comfortable type inference
  • Immer in the first class support
  • 🍳 150 line code based on Zustand
  • 🧮 Modular state management (Redux-like)
  • 📖 Scope supported with Algebraic Effects

Quick Start

You can try it on StackBlitz or CodeSandbox

Or install locally

yarn add immer zustand # peer dependencies
yarn add zoov

First Glance

const CounterModule = defineModule({ count: 0 })
  .actions({
    add: (draft) => draft.count++,
    minus: (draft) => draft.count--,
  })
  .computed({
    doubled: (state) => state.count * 2,
  })
  .build();

const App = () => {
  const [{ count }, { add }] = CounterModule.use();
  return <button onClick={add}>{count}</button>;
};

// state is shared
const App2 = () => {
  const { doubled } = CounterModule.useComputed();
  return <div>doubled: {doubled}</div>;
};

More Examples

Use Methods

const CounterModule = defineModule({ count: 0 })
  .actions({
    add: (draft) => draft.count++,
    minus: (draft) => draft.count--,
  })
  .computed({
    doubled: (state) => state.count * 2,
  })
  .methods(({ getActions }) => {
    const { add, minus } = getActions();
    return {
      addAndMinus: () => {
        add();
        add();
        setTimeout(() => minus(), 100);
      },
      // async function is supported
      asyncAdd: async () => {
        await something()
        add()
      },
      // !rxjs is required if you want to use effect, import from 'zoov/utils'
      addAfter: effect<number>((payload$) =>
        payload$.pipe(
          exhaustMap((timeout) => {
            return timer(timeout).pipe(tap(() => add()));
          })
        )
      ),
    };
  })
  .build();

Use Selector

const CounterModule = defineModule({ count: 0, input: 'hello' })
  .actions({
    add: (draft) => draft.count++,
    setInput: (draft, value: string) => (draft.input = value),
  })
  .build();

const App = () => {
  // <App /> will not rerender unless "count" changes
  const [count] = CounterModule.use((state) => state.count);
  return <span>{count}</span>;
};

Use Middleware

// see more examples in https://github.com/pmndrs/zustand/blob/master/src/middleware.ts
const Module = defineModule({ count: 0 })
  .actions({ add: (draft) => draft.count++ })
  .middleware((store) => persist(store, { name: 'counter' }))
  .build();

Use default setState Action

// a lite copy of solid-js/store, with strict type check
const Module = defineModule({ count: 0, nested: { checked: boolean } }).build();

const [{ setState }] = Module.useActions()

setState('count', 1)
setState('nested', 'checked', v => !v)

Use Provider

import { defineProvider } from 'zoov';

const CustomProvider = defineProvider((handle) => {
  // create a new Module scope for all its children(can be nested)
  handle(YourModule, {
    defaultState: {},
  });
  handle(AnotherModule, {
    defaultState: {},
  });
});

const App = () => {
  // if a Module is not handled by any of its parent, then used global scope
  return (
    <div>
      <CustomProvider>
        <Component />
      </CustomProvider>
      <Component />
    </div>
  );
};
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].