+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@saul-atomrigs/react",
"version": "0.2.0",
"version": "0.3.2",
"type": "module",
"description": "React utils for faster project development",
"main": "./dist/index.js",
Expand Down Expand Up @@ -51,8 +51,10 @@
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.3.1",
"@rollup/plugin-typescript": "^11.1.6",
"@tanstack/react-query": "^5.68.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.2.0",
"@testing-library/user-event": "^14.6.1",
"@types/jest": "^29.5.14",
"@types/react": "^17.0.0 || ^18.0.0",
"@types/react-dom": "^17.0.0 || ^18.0.0",
Expand All @@ -63,6 +65,7 @@
"jsdom": "^26.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^5.0.0",
"rollup": "^4.9.6",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-typescript2": "^0.36.0",
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './create-context';
export * from './query-async-boundary';
33 changes: 33 additions & 0 deletions src/query-async-boundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { Suspense, type PropsWithChildren } from 'react';
import { useQueryErrorResetBoundary } from '@tanstack/react-query';
import { ErrorBoundary } from 'react-error-boundary';

type QueryAsyncBoundaryProps = {
pendingFallback: React.ReactNode;
rejecterFallback?: React.ReactNode;
} & PropsWithChildren;

/**
* reference: https://github.com/ssi02014/react-query-tutorial?tab=readme-ov-file#usequeryerrorresetboundary
* PLEASE use throwOnError: true in the query options to make sure the error is thrown and caught by the error boundary.
*/
export const QueryAsyncBoundary = ({
pendingFallback,
rejecterFallback,
children,
}: QueryAsyncBoundaryProps) => {
const { reset } = useQueryErrorResetBoundary();

return (
<ErrorBoundary
onReset={reset}
fallbackRender={({ resetErrorBoundary }) =>
rejecterFallback || (
<button onClick={() => resetErrorBoundary()}>Try again</button>
)
}
>
<Suspense fallback={pendingFallback}>{children}</Suspense>
</ErrorBoundary>
);
};
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载