mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 16:43:25 +00:00
20 lines
444 B
TypeScript
20 lines
444 B
TypeScript
import { useMemo, useState } from "react";
|
|
|
|
type InitialState = boolean | (() => boolean);
|
|
|
|
export const useBoolean = (initialState: InitialState = false) => {
|
|
const [value, setValue] = useState(initialState);
|
|
const callbacks = useMemo(
|
|
() => ({
|
|
on: () => setValue(true),
|
|
off: () => setValue(false),
|
|
toggle: () => setValue((prev) => !prev),
|
|
}),
|
|
[],
|
|
);
|
|
return {
|
|
isTrue: value,
|
|
...callbacks,
|
|
};
|
|
};
|