All files / packages/app/hooks use-boolean-state.ts

100% Statements 10/10
100% Branches 1/1
100% Functions 5/5
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13    46944x 53723x 53723x 53723x 53723x 48x     53723x    
import React from "react";
 
export const useBooleanState = (initialValue = false) => {
	const [value, setValue] = React.useState(initialValue);
	const setTrue = React.useCallback(() => setValue(true), [setValue]);
	const setFalse = React.useCallback(() => setValue(false), [setValue]);
	const switchValue = React.useCallback(
		() => setValue((prev) => !prev),
		[setValue],
	);
	return [value, { setTrue, setFalse, switchValue }] as const;
};