@st-lib/use-async-memo
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

React useMemo for async functions

import * as React from 'react'
import useAsyncMemo from '@st-lib/use-async-memo'

export default function Component() {
	const task = useAsyncMemo(async () => {
		/* do some work */
	})

	if (null != task.result) {
		return (
			<span>
				{/* use result here */}
			</span>
		)
	} else if (null != task.error) {
		return (
			<span className='error'>
				{task.error.message}
			</span>
		)
	} else {
		return (
			<span>
				{'Loading'}
			</span>
		)
	}
}

/@st-lib/use-async-memo/

    Package Sidebar

    Install

    npm i @st-lib/use-async-memo

    Weekly Downloads

    4

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    3.59 kB

    Total Files

    5

    Last publish

    Collaborators

    • st-lib