mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
19 lines
355 B
TypeScript
19 lines
355 B
TypeScript
import { useMemo } from 'react';
|
|
|
|
/**
|
|
* Track the state of a boolean and return values based on its state.
|
|
*/
|
|
export function useBooleanValue<T extends any, F extends any>(
|
|
status: boolean,
|
|
ifTrue: T,
|
|
ifFalse: F,
|
|
): T | F {
|
|
return useMemo(() => {
|
|
if (status) {
|
|
return ifTrue;
|
|
} else {
|
|
return ifFalse;
|
|
}
|
|
}, [status]);
|
|
}
|