mirror of
https://github.com/sasjs/server.git
synced 2026-01-16 02:10:05 +00:00
chore(web): move hooks to hooks folder
This commit is contained in:
2
web/src/utils/hooks/index.ts
Normal file
2
web/src/utils/hooks/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './usePrompt'
|
||||||
|
export * from './useStateWithCallback'
|
||||||
@@ -2,7 +2,7 @@ import { useEffect, useCallback, useContext } from 'react'
|
|||||||
import { UNSAFE_NavigationContext as NavigationContext } from 'react-router-dom'
|
import { UNSAFE_NavigationContext as NavigationContext } from 'react-router-dom'
|
||||||
import { History, Blocker, Transition } from 'history'
|
import { History, Blocker, Transition } from 'history'
|
||||||
|
|
||||||
function useBlocker(blocker: Blocker, when = true) {
|
const useBlocker = (blocker: Blocker, when = true) => {
|
||||||
const navigator = useContext(NavigationContext).navigator as History
|
const navigator = useContext(NavigationContext).navigator as History
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -24,7 +24,7 @@ function useBlocker(blocker: Blocker, when = true) {
|
|||||||
}, [navigator, blocker, when])
|
}, [navigator, blocker, when])
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function usePrompt(message: string, when = true) {
|
export const usePrompt = (message: string, when = true) => {
|
||||||
const blocker = useCallback(
|
const blocker = useCallback(
|
||||||
(tx) => {
|
(tx) => {
|
||||||
if (window.confirm(message)) tx.retry()
|
if (window.confirm(message)) tx.retry()
|
||||||
Reference in New Issue
Block a user