mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: deprecate hacky did-update
This commit is contained in:
parent
d4e4f77777
commit
be6d95355c
2 changed files with 14 additions and 3 deletions
|
|
@ -14,6 +14,7 @@ import * as React from 'react'
|
|||
import { cx } from 'utils/cx'
|
||||
import * as DOMHelper from 'utils/DOMHelper'
|
||||
import { JSONRequest, parseURLSearch } from 'utils/general'
|
||||
import { useDidUpdate } from 'utils/hooks'
|
||||
import * as keyHelper from 'utils/keyHelper'
|
||||
|
||||
const RawGitako: React.FC<Props & ConnectorState> = function RawGitako(props) {
|
||||
|
|
@ -60,9 +61,8 @@ const RawGitako: React.FC<Props & ConnectorState> = function RawGitako(props) {
|
|||
DOMHelper.decorateGitHubPageContent({ copyFileButton, copySnippetButton })
|
||||
}, [])
|
||||
|
||||
// reload when setting new accessToken
|
||||
// special way to implement didUpdate
|
||||
React.useEffect(() => () => props.init(), [accessToken])
|
||||
// init again when setting new accessToken
|
||||
useDidUpdate(() => props.init(), [accessToken])
|
||||
|
||||
const {
|
||||
errorDueToAuth,
|
||||
|
|
|
|||
|
|
@ -68,3 +68,14 @@ export function useAsyncMemo<T, D extends any[] | readonly any[]>(
|
|||
}, deps)
|
||||
return state.val
|
||||
}
|
||||
|
||||
export function useDidUpdate(effect: React.EffectCallback, deps?: React.DependencyList) {
|
||||
const firstTime = React.useRef(true)
|
||||
React.useEffect(() => {
|
||||
if (firstTime.current) {
|
||||
firstTime.current = false
|
||||
return
|
||||
}
|
||||
return effect()
|
||||
}, deps)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue