-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60d5cbf
commit 35a1bb1
Showing
9 changed files
with
319 additions
and
230 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react' | ||
|
||
import { useMergedRefs } from '../../../lib' | ||
import validateTrigger from './validateTrigger' | ||
|
||
/** | ||
* @param {React.ReactNode} trigger | ||
* @param {React.Ref} triggerRef | ||
*/ | ||
function useTrigger(trigger, triggerRef) { | ||
const ref = useMergedRefs(trigger?.ref, triggerRef) | ||
|
||
if (trigger) { | ||
/* istanbul ignore else */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
validateTrigger(trigger) | ||
} | ||
|
||
return [ref, React.cloneElement(trigger, { ref })] | ||
} | ||
|
||
return [ref, null] | ||
} | ||
|
||
export default useTrigger |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react' | ||
|
||
/** | ||
* Hook keeping track of a given value from a previous execution of the component the Hook is used in. | ||
* | ||
* @see https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state | ||
*/ | ||
function usePrevious(value) { | ||
const ref = React.useRef() | ||
|
||
React.useEffect(() => { | ||
ref.current = value | ||
}) | ||
|
||
return ref.current | ||
} | ||
|
||
export default usePrevious |
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
Oops, something went wrong.