[Session] Add useAgent hook and replace (#3706)

* Hook it up

* Memoize getAgent method

* Use one shared reference

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
This commit is contained in:
Eric Bailey
2024-04-25 16:29:05 -05:00
committed by GitHub
parent d8c8e1e854
commit 45d354cd0c
53 changed files with 231 additions and 114 deletions
@@ -1,12 +1,14 @@
import {useState, useEffect} from 'react'
import {useEffect, useState} from 'react'
import {useAgent} from '#/state/session'
import * as apilib from 'lib/api/index'
import {getLinkMeta} from 'lib/link-meta/link-meta'
import {ComposerOpts} from 'state/shell/composer'
import {getAgent} from '#/state/session'
export function useExternalLinkFetch({}: {
setQuote: (opts: ComposerOpts['quote']) => void
}) {
const {getAgent} = useAgent()
const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>(
undefined,
)
@@ -39,7 +41,7 @@ export function useExternalLinkFetch({}: {
})
}
return cleanup
}, [extLink])
}, [extLink, getAgent])
return {extLink, setExtLink}
}