react-use
react-use copied to clipboard
OR / AND operator hooks!
Hello, I need a hook that has a boolean value with OR / AND operator. Like below
useOR
const [a, setA] = useState(false)
const [b, setB] = useState(false)
return { value: a || b, setA, setB }
useAND
const [a, setA] = useState(false)
const [b, setB] = useState(false)
return { value: a && b, setA, setB }
I think these are good micro utility hook for solving diverse state problem.
But I cannot name it, I wanna name it with good metaphor like useToggle.
Is anybody has a idea or know already existing solution, please let me know. Thanks !
Can you give an example of usage of the api you want?
@childrentime
Thanks for the interest.
I have some business logics the use or state like below.
const useIsUserActive = () => {
const { value, setA, setB } = useOR();
// when user is in page
setA(isUserInPage);
// when user mouse moved in 30 seconds.
setB(hasUserMoved);
// isUserActive
return value;
}