Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suspensive.org): add Sandpack component (#963)
# Overview <!-- A clear and concise description of what this pr is about. --> related #867 closed #7 I have set up the documentation to easily add examples in MDX using Sandpack from CodeSandbox. I have also carried over the theme selected in the [related PR](#867). If there's anything else that needs to be configured, please let me know! ## Usage ````mdx import { Sandpack } from '@/components' <Sandpack customSetup={{ dependencies: { '@suspensive/react': 'latest', '@suspensive/react-query': 'latest', '@tanstack/react-query': '^4.0.0', }, }} > ```js /App.tsx import Example from './Example' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' const queryClient = new QueryClient() export default function App() { return ( <QueryClientProvider client={queryClient}> <Example /> </QueryClientProvider> ) } ``` ```js /Example.tsx active import { wrap } from '@suspensive/react' import { useSuspenseQuery } from '@suspensive/react-query' import { api } from './api' export default wrap .ErrorBoundaryGroup({ blockOutside: false }) .ErrorBoundary({ fallback: ({ error }) => <>{error.message}</> }) .Suspense({ fallback: <>loading...</>, clientOnly: true }) .on(() => { const query = useSuspenseQuery({ queryKey: ['key'], queryFn: () => api.text(), }) return <>{query.data.text}</> }) ``` ```js /api.ts export const api = { text: async () => { await new Promise((resolve) => setTimeout(resolve, 1000)) return { text: 'Hello, Suspensive!' } }, } ``` </Sandpack> ```` ### Result https://github.com/toss/suspensive/assets/23312485/370b6508-cd9b-494d-8ea6-28273eaabba8 ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
- Loading branch information