
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
github.com/awmleer/use-async-memo
React hook for generating async memoized data.
function useAsyncMemo<T>(factory: () => Promise<T>, deps: DependencyList, initial?: T): T
If factory
returns undefined
or null
, useAsyncMemo
will leave the memoized value unchanged.
import {useAsyncMemo} from "use-async-memo"
const data = useAsyncMemo(doAPIRequest, [])
or
const data = useAsyncMemo(() => doAPIRequest(), [])
or
const data = useAsyncMemo(() => {
return doAPIRequest()
}, [])
or
const data = useAsyncMemo(async () => {
return await doAPIRequest()
}, [])
const [input, setInput] = useState()
const users = useAsyncMemo(async () => {
if (input === '') return []
return await apiService.searchUsers(input)
}, [input], [])
const [loading, setLoading] = useState(true)
const data = useAsyncMemo(async () => {
setLoading(true)
const response = await doAPIRequest()
setLoading(false)
return response
}, [])
const [input, setInput] = useState()
const [clearFlag, setClearFlag] = useState({
val: false
})
function clearItems() {
setClearFlag({
val: true
})
}
const users = useAsyncMemo(async () => {
if (clearFlag.val) {
clearFlag.val = false
return null
}
if (input === '') return []
return await apiService.searchUsers(input)
}, [input, clearFlag], [])
see use-debounce
const [input, setInput] = useState()
const [debouncedInput] = useDebounce(input, 300)
const users = useAsyncMemo(async () => {
if (debouncedInput === '') return []
return await apiService.searchUsers(debouncedInput)
}, [debouncedInput], [])
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.