Fix useMemo returns new component on change (#2315)
This fixes setting the input value on scan if the component remounts while the scanner is open. No need to use useRef to close the scanner on remount.
This commit is contained in:
parent
243b094fcd
commit
3f74279f29
@ -1350,21 +1350,11 @@ function PasswordScanner ({ onScan, text }) {
|
|||||||
loading: () => <PageLoading />
|
loading: () => <PageLoading />
|
||||||
})
|
})
|
||||||
|
|
||||||
const closeRef = useRef()
|
|
||||||
useEffect(() => {
|
|
||||||
return () => {
|
|
||||||
// close modal on remount to avoid calling stale callbacks
|
|
||||||
// see https://github.com/stackernews/stacker.news/pull/2313
|
|
||||||
closeRef.current?.()
|
|
||||||
}
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InputGroup.Text
|
<InputGroup.Text
|
||||||
style={{ cursor: 'pointer' }}
|
style={{ cursor: 'pointer' }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
showModal(onClose => {
|
showModal(onClose => {
|
||||||
closeRef.current = onClose
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{text && <h5 className='line-height-md mb-4 text-center'>{text}</h5>}
|
{text && <h5 className='line-height-md mb-4 text-center'>{text}</h5>}
|
||||||
|
@ -49,7 +49,7 @@ export default function Wallet () {
|
|||||||
? (
|
? (
|
||||||
<WalletLayout>
|
<WalletLayout>
|
||||||
<div className='py-5 d-flex flex-column align-items-center justify-content-center flex-grow-1 mx-auto' style={{ maxWidth: '500px' }}>
|
<div className='py-5 d-flex flex-column align-items-center justify-content-center flex-grow-1 mx-auto' style={{ maxWidth: '500px' }}>
|
||||||
<PassphrasePrompt />
|
{PassphrasePrompt}
|
||||||
</div>
|
</div>
|
||||||
</WalletLayout>
|
</WalletLayout>
|
||||||
)
|
)
|
||||||
|
@ -238,8 +238,7 @@ export function usePassphrasePrompt () {
|
|||||||
const [showPassphrasePrompt, setShowPassphrasePrompt] = useState(false)
|
const [showPassphrasePrompt, setShowPassphrasePrompt] = useState(false)
|
||||||
const togglePassphrasePrompt = useCallback(() => setShowPassphrasePrompt(v => !v), [])
|
const togglePassphrasePrompt = useCallback(() => setShowPassphrasePrompt(v => !v), [])
|
||||||
|
|
||||||
const Prompt = useMemo(() =>
|
const Prompt = useMemo(() => (
|
||||||
() => (
|
|
||||||
<div>
|
<div>
|
||||||
<h4>Wallet decryption</h4>
|
<h4>Wallet decryption</h4>
|
||||||
<p className='line-height-md mt-3'>
|
<p className='line-height-md mt-3'>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user