react-client-async
Advanced tools
Comparing version 1.3.4 to 1.3.5
@@ -1,2 +0,2 @@ | ||
import { useCallback, useEffect, useRef, useState } from 'react'; | ||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; | ||
import sameProps from '../utils/sameProps'; | ||
@@ -49,3 +49,3 @@ /** | ||
// The state of the async function. | ||
state: { pending, result, error }, | ||
state: useMemo(() => ({ pending, result, error }), [pending, result, error]), | ||
// The load function to run the async function. | ||
@@ -66,3 +66,3 @@ load: useCallback(() => { | ||
const sameRefresh = refreshRef.current === refresh; | ||
const notFirstRun = pending !== undefined || !options.autoLoad; | ||
const notFirstRun = pending != null || !options.autoLoad; | ||
const noChange = sameFn && sameArgs && sameRefresh && notFirstRun; | ||
@@ -69,0 +69,0 @@ const reason = abortCtlRef.current?.signal.reason; |
{ | ||
"name": "react-client-async", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"main": "dist/lib.js", | ||
@@ -44,11 +44,11 @@ "module": "dist/lib.js", | ||
"peerDependencies": { | ||
"react": "^17 || ^18 || ^19", | ||
"react-dom": "^17 || ^18 || ^19" | ||
"react": "^19.0.0", | ||
"react-dom": "^19.0.0" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.9.4", | ||
"@rsbuild/core": "^1.2.4", | ||
"@rsbuild/core": "^1.2.8", | ||
"@rsbuild/plugin-mdx": "^1.0.2", | ||
"@rsbuild/plugin-react": "^1.1.0", | ||
"@tailwindcss/postcss": "^4.0.3", | ||
"@tailwindcss/postcss": "^4.0.6", | ||
"@tailwindcss/typography": "^0.5.16", | ||
@@ -61,3 +61,3 @@ "@types/gh-pages": "^6.1.0", | ||
"gh-pages": "^6.3.0", | ||
"postcss": "^8.5.1", | ||
"postcss": "^8.5.2", | ||
"postcss-load-config": "^6.0.1", | ||
@@ -68,3 +68,3 @@ "postcss-loader": "^8.1.1", | ||
"react-toastify": "^11.0.3", | ||
"tailwindcss": "^4.0.3", | ||
"tailwindcss": "^4.0.6", | ||
"tsc-alias": "^1.8.10", | ||
@@ -71,0 +71,0 @@ "typescript": "^5.7.3" |
@@ -15,5 +15,5 @@ <h1 align="center"> | ||
## ๐ Introduction | ||
This package helps you use async function **<u>without</u>** the need to migrate to `โ๏ธ React 19` and server-side rendering! | ||
@@ -24,2 +24,3 @@ | ||
## ๐ Install | ||
@@ -41,2 +42,19 @@ | ||
## โ `useAsyncMemo` Hook | ||
Use the `useAsyncMemo` hook to create a memoized async task. | ||
```tsx | ||
const { | ||
load, stop, | ||
state: { result, pending, error } | ||
} = useAsyncMemo(({ signal }) => | ||
fetch("/package.json", { signal }) | ||
.then((res) => res.json()), | ||
[/* Function Dependencies */], | ||
{ autoLoad: false }, | ||
); | ||
``` | ||
## โ `Async` Component | ||
@@ -55,4 +73,5 @@ | ||
## ๐ฌ `Demo` of Recursive Async Component | ||
## ๐ฌ Recursive Async Component Demo | ||
Easy to `wrap` a recursive async component and memoize it. | ||
@@ -74,2 +93,3 @@ | ||
## โณ What is Next? | ||
@@ -76,0 +96,0 @@ |
18895
123