deno.land / x / solid_signals@solid-signals@1.3.7 / src / signals / composable / createSet

Composable signal: createSet

Extends signal setter with set, delete and clear methods. See Reference for more details.

Usage

Basic

import { createSet } from "solid-signals";

function ExampleComponent {
  const [set, setSet] = createSet(new Set<number>());

  return (
    <div>
      <button onClick={() => {
        setSet.add(set().size);
      }}>
        Add
      </button>
      set: {JSON.stringify([...set()])}
    </div>
  );
}

Result

set: []

[Click: Add]
set: [0]

[Click: Add]
set: [0, 1]

Composition

import { createHistory, createSet } from "solid-signals";

function ExampleComponent {
  const [set, setSet] = createSet.wrap(createHistory({ prop1: "value1", prop2: "value2" }));

  return (
    <div>
      <button onClick={() => {
        setSet.add(set().size);
      }}>
        Add
      </button>
      <button onClick={() => {
        setSet.history.back();
      }}>
        Back
      </button>
      set: {JSON.stringify([...set()])}
    </div>
  );
}

Result

set: []

[Click: Add]
set: [0]

[Click: Add]
set: [0, 1]

[Click: Back]
set: [0]

[Click: Back]
set: []

Reference

Set methods

The following methods use the same api as the built-in JavaScript Set, the following links lead to MDN.

solid_signals

Version Info

Tagged at
a year ago