Skip to main content

Built and signed on GitHub Actions

Utility functions and hooks for a variety of React-style frameworks.

This package works with Node.js, Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers, Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
100%
Published
3 months ago (0.4.0)
function setInteger
setInteger<T>(
callback: (value: T | number) => void,
orElse?: T | setterDontSet,
): (e: EventLike) => void

Returns an event handler that will call the callback with the value of the target element as a integer. If the value is not a valid integer, the callback will not be called, unless orElse is provided, in which case the callback will be called with that value.

Examples

Example 1

const [value, setValue] = useState(0);
return <input type="number" value={value} onChange={setinteger(setValue)} />;
// If the input is not a valid integer, `setValue` will not be called.

Example 2

const [value, setValue] = useState<number | null>(0);
return <input type="number" value={value ?? ""} onChange={setinteger(setValue, null)} />;
// If the input is not a valid integer, `setValue` will be called with `null`.

Type Parameters

Parameters

callback: (value: T | number) => void

The setter function to be called.

optional
orElse: T | setterDontSet = setterDontSet

If set, this value will be passed to the callback if the input is not a valid integer.

Return Type

(e: EventLike) => void

Add Package

deno add jsr:@lixquid/util-react

Import symbol

import { setInteger } from "@lixquid/util-react";

---- OR ----

Import directly with a jsr specifier

import { setInteger } from "jsr:@lixquid/util-react";

Add Package

npx jsr add @lixquid/util-react

Import symbol

import { setInteger } from "@lixquid/util-react";

Add Package

yarn dlx jsr add @lixquid/util-react

Import symbol

import { setInteger } from "@lixquid/util-react";

Add Package

pnpm dlx jsr add @lixquid/util-react

Import symbol

import { setInteger } from "@lixquid/util-react";

Add Package

bunx jsr add @lixquid/util-react

Import symbol

import { setInteger } from "@lixquid/util-react";