Created
March 9, 2021 17:43
-
-
Save aidangarza/cf315ca14ec139bf54f577e8ec9a0790 to your computer and use it in GitHub Desktop.
A hook for locking access to any subject to prevent multiple components from overwriting a piece of shared state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In the style of useRef, the locks variable has a | |
// current property which is an object that will | |
// store the current lockout state of different features | |
const locks = { | |
current: {} | |
}; | |
export default function useLockout(feature) { | |
const lockout = (shouldLock = true) => { | |
locks.current[feature] = shouldLock; | |
}; | |
return [ | |
() => locks.current[feature], | |
lockout | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment