Skip to content

Commit

Permalink
Bump version to 1.3.0 and rename sampArgs to sameArgs for consistency…
Browse files Browse the repository at this point in the history
… in Async component and useAsync hook
  • Loading branch information
HK-SHAO committed Jan 26, 2025
1 parent 7f79ad7 commit dcff359
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-client-async",
"version": "1.2.2",
"version": "1.3.0",
"main": "dist/lib.js",
"module": "dist/lib.js",
"files": ["dist/", "README.md", "LICENSE"],
Expand Down
2 changes: 1 addition & 1 deletion src/libs/components/Async.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function Async<P>({
// Create the options for the async function.
const options = {
autoLoad: true,
sampArgs: sameArgs,
sameArgs,
} satisfies UseAsyncOptions<P>;

// Execute the async function and get the state.
Expand Down
6 changes: 3 additions & 3 deletions src/libs/hooks/useAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type UseAsyncObject<P> = {
/**
* Determine the arguments are the same.
*/
sampArgs: propsAreEqual<P>;
sameArgs: propsAreEqual<P>;
};

type UseAsyncOptions<P> = Partial<UseAsyncObject<P>>;
Expand Down Expand Up @@ -108,7 +108,7 @@ function useAsync<Args, Ret>(
): UseAsyncReturn<Ret> {
// Set default options
options.autoLoad ??= false;
options.sampArgs ??= sameProps;
options.sameArgs ??= sameProps;

const [pending, setPending] = useState<boolean>();
const [result, setResult] = useState<Ret>();
Expand Down Expand Up @@ -148,7 +148,7 @@ function useAsync<Args, Ret>(

// Check if no need to rerun the async function.
const sameFn = fnRef.current === promiseFn;
const sameArgs = options.sampArgs?.(argsRef.current, args);
const sameArgs = options.sameArgs?.(argsRef.current, args);
const sameRefresh = refreshRef.current === refresh;
const notFirstRun = pending !== undefined || !options.autoLoad;
const noChange = sameFn && sameArgs && sameRefresh && notFirstRun;
Expand Down

0 comments on commit dcff359

Please sign in to comment.