Skip to the content

Tane種

Reproduce numbers from a seed, shuffle or pick items, share a daily puzzle and resume a saved stream.

Tane means seed in Japanese. About the name

Contents

Reference · React hooks

useSeededfunction

Something made once from a seeded stream, and made again only when the seed changes: useSeeded(seed, (random) => shuffled(random, deck)). The stream is fresh each time, so the result depends on the seed alone, never on how many times the component rendered. make is read when the seed changes; for anything else it depends on, give the component a key.

Import it

import { useSeeded } from "@johnmorrisdotca/tane/react";

Definition

function useSeeded<T>(seed: number, make: (random: Random) => T): T

Parameters

NameTypeDescription
seednumber

The numeric seed, read as an unsigned 32-bit integer by the stream.

make(random: Random) => T

A callback that builds a value from the fresh seeded stream.

Returns

T

The value built from the seeded stream, retained until the seed changes.

Examples

import { useSeeded } from "@johnmorrisdotca/tane/react";
import { pick } from "@johnmorrisdotca/tane";

import { createElement } from "react";
function Choice() {
  const choice = useSeeded(42, (random) => pick(random, ["A", "B", "C"]));
  return createElement("p", null, choice);
}
console.log(createElement(Choice));

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/tane 1.3.0.