Skip to content

Commit

Permalink
style: error boundary for demo page
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyshlyaev177 committed Nov 13, 2024
1 parent 969e30a commit ad4647b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
34 changes: 15 additions & 19 deletions package-lock.json

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

1 change: 1 addition & 0 deletions packages/example-nextjs14/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"next": "^14.2.16",
"react": "^18",
"react-dom": "^18",
"react-error-boundary": "^4.1.2",
"react-share": "^5.1.0",
"schema-dts": "^1.1.2",
"shiki": "^1.12.1"
Expand Down
21 changes: 19 additions & 2 deletions packages/example-nextjs14/src/app/DemoPart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client'
import React from 'react';
import { usePathname } from 'next/navigation';
import { ErrorBoundary, type FallbackProps } from "react-error-boundary";

import { GithubLink } from './components/GithubLink';
import { UrlBox } from './components/UrlBox';
Expand Down Expand Up @@ -39,15 +40,31 @@ export function DemoPart({ searchParams }: { searchParams: object }) {

<section className="form-components">
<React.Suspense>
<Form className="form" searchParams={searchParams} ghLink={urls.form} />
<Status className="status" sp={searchParams} ghLink={urls.status} />
<ErrorBoundary fallbackRender={fallbackRender}>
<Form className="form" searchParams={searchParams} ghLink={urls.form} />
</ErrorBoundary>
<ErrorBoundary
fallbackRender={fallbackRender}>
<Status className="status" sp={searchParams} ghLink={urls.status} />
</ErrorBoundary>

</React.Suspense>
</section>
</section>
</>
);
}

function fallbackRender({ error, resetErrorBoundary }: FallbackProps) {
return (
<div role="alert" className='max-w-[30%] flex flex-col items-center gap-4'>
<p>Something went wrong:</p>
<pre className='whitespace-break-spaces text-red-500 max-h-[350px]'>{error.message || error}</pre>
<button onClick={resetErrorBoundary} className='p-4 bg-gray-300 rounded-md'>Try again</button>
</div>
);
}

const sourceUrls = {
next: {
form: 'https://github.com/asmyshlyaev177/state-in-url/blob/master/packages/example-nextjs14/src/app/Form.tsx',
Expand Down

0 comments on commit ad4647b

Please sign in to comment.