Socket
Socket
Sign inDemoInstall

zustand-sliver

Package Overview
Dependencies
9
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    zustand-sliver

Zustand slices like redux-toolkit


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Use Tiamut instead




Zustand Sliver

This package was build to provide zustand with redux-toolkit like api with some opinionated utilities

Usage

Install

npm i --save zustand-sliver

Create a sliver

import { createSliver } from 'zustand-sliver';

const bearSliver = createSliver({
  initialState: {
    firstName: 'Ted',
    lastName: 'Day',
  },
  selectors: {
    fullName(state) {
      return state.firstName + ' ' + state.lastName;
    },
  },
  actions: {
    updateFirstName(state, value: string) {
      state.firstName = value;
    },
  },
});

Create store hook

import { createStore } from 'zustand-sliver';

const store = createStore({
  bear: bearSliver,
});

Use as hook

function MyApp() {
  const firstName = store((state) => state.bear.firstName);
  const fullName = store.use.bear.fullName();
  const updateFirstName = store.actions.bear.updateFirstName;

  function changeFirstName() {
    updateFirstName('Ted ' + new Date().valueOf());
  }

  return (
    <div>
      <div>firstName: {firstName}</div>
      <div>fullName: {fullName}</div>
      <button onClick={changeFirstName}>Update Name</button>
    </div>
  );
}

FAQs

Last updated on 05 Sep 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc