1.1.16 • Published 1 year ago

@fipnooone/hooks v1.1.16

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

React Hooks

Usage

import {
	useCallbackState,
	useEvents,
	useObjectCallback,
	useObjectEffect,
	useObjectMemo,
	useOutside,
	useParams,
	usePromiseState,
	useTrustedPromise,
	useTrustedState,
} from "@fipnooone/hooks";

useState

useTrustedState

const [state, setState, isTrusted] = useTrustedState("defaultValue", true);
const [state, setState, isTrusted] = useTrustedState();

useCallbackState

const [state, setState] = useCallbackState("defaultValue");

const changeCallback = (value: string) => console.log(value);

const changeState = () => setState("newValue", changeCallback);

usePromiseState

const [state, setState] = usePromiseState<User>();

const changeState = () =>
	setState({ username: "fipnooone", website: "https://fipnoo.one" }).then((value) => {
		console.log(value);
	});

useTrustedPromise

const [state, setState] = useTrustedPromise<number>();

const changeState = () => setState(undefined).then();

useParams

const { id, station_slug } = useParams({ id: 'int', station_slug: 'string' });
// id: number
// station_slug: string

// redirect is true by refault
useParams({ }, redirect: boolean | '/url/to/a-page');

const { id, station_slug } = useParams({ id: 'int', station_slug: 'string' }, false);
// id: number | undefined
// station_slug: string | undefined

useObject

useObjectEffect / useObjectCallback / useObjectMemo

const [users, setUsers] = useState<User[]>([]);

useObjectEffect(() => {
	// ...
}, [users]);

useCallback

useOutside

useOutside(myRef, () => close(), [dep]);

useEvents

useEvents(
	"click",
	(event) => {
		while (true) {
			console.log("clicked");
		}
	},
	[dep0, dep1],
	document
);

useRef

useRefEffect

useRefEffect((T) => {}, ref<T>, [dep]);

useEvents

useRefReady((T) => {}, ref<T>);
1.1.16

1 year ago

1.1.15

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago