1.1.16 • Published 2 years ago

@fipnooone/hooks v1.1.16

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years 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

2 years ago

1.1.15

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago