mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-14 20:50:57 -05:00
5b0c122f5d
List of user emails GitOrigin-RevId: 28a8e405812932ba7ebd8043a4dc9d3c573a68b2
17 lines
384 B
TypeScript
17 lines
384 B
TypeScript
import * as React from 'react'
|
|
import useIsMounted from './use-is-mounted'
|
|
|
|
function useSafeDispatch<T>(dispatch: React.Dispatch<T>) {
|
|
const mounted = useIsMounted()
|
|
|
|
return React.useCallback<(args: T) => void>(
|
|
action => {
|
|
if (mounted.current) {
|
|
dispatch(action)
|
|
}
|
|
},
|
|
[dispatch, mounted]
|
|
) as React.Dispatch<T>
|
|
}
|
|
|
|
export default useSafeDispatch
|