New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

immer-svelte

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immer-svelte

Use immer with Svelte

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

immer-svelte

npm version Build Status

Installation

npm i -S immer immer-svelte

or

yarn add immer immer-svelte

API

useImmer

The function returns a tuple, the first value of the tuple is the current state, the second is the updater function, which accepts an immer producer function, in which the draft can be mutated freely, until the producer ends and the changes will be made immutable and become the next state.

<script>
  import { useImmer } from "immer-svelte";

  const [state, updateState] = useImmer({ count: 0 });

  function increase() {
    updateState(draft => {
      draft.count++;
    });
  }
</script>

<div>Count: {$state.count}</div>
<button on:click={increase}>Increase</button>
useImmerReducer
<script>
  import { useImmerReducer } from "immer-svelte";

  const initialState = { count: 0 };

  function reducer(draft, action) {
    switch (action.type) {
      case "reset":
        return initialState;
      case "increment":
        return void draft.count++;
      case "decrement":
        return void draft.count--;
    }
  }

  const [state, dispatch] = useImmerReducer(reducer, initialState);
</script>

<div>
  Count: {$state.count}
  <button on:click={() => dispatch({ type: "reset" })}>Reset</button>
  <button on:click={() => dispatch({ type: "increment" })}>+</button>
  <button on:click={() => dispatch({ type: "decrement" })}>-</button>
</div>

Keywords

FAQs

Package last updated on 28 Mar 2020

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