mirror of
https://github.com/lux-tel/websites.git
synced 2026-10-30 20:31:36 +00:00
15 lines
528 B
TypeScript
15 lines
528 B
TypeScript
import { type DependencyList, useEffect } from 'react';
|
|
|
|
/**
|
|
* Executes an effect if all dependencies are truthy
|
|
* @param callback The effect callback
|
|
* @param conditions The condition dependency array
|
|
*/
|
|
export const useConditional = (callback: () => void, conditions: DependencyList) =>
|
|
// biome-ignore lint/correctness/useExhaustiveDependencies: callback and conditions array have to be constant
|
|
useEffect(() => {
|
|
if (conditions.every((condition) => !!condition)) {
|
|
return callback;
|
|
}
|
|
}, conditions);
|