Skip to content

Commit

Permalink
Merge pull request #9 from depromeet/feat/async
Browse files Browse the repository at this point in the history
feat: 비동기 처리를 위한 유틸 함수 구현
  • Loading branch information
Collection50 authored Jul 19, 2024
2 parents 64b99d6 + 081ec51 commit 5148b39
Show file tree
Hide file tree
Showing 50 changed files with 689 additions and 45 deletions.
24 changes: 23 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,30 @@
"plugin:storybook/recommended"
],
"rules": {
"import/order": [
"warn",
{
"groups": ["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"],
"pathGroups": [
{
"pattern": "next",
"group": "builtin",
"position": "before"
},
{
"pattern": "~/**",
"group": "external",
"position": "after"
}
]
}
],
"@typescript-eslint/consistent-type-imports": "warn",
"prettier/prettier": ["warn", { "printWidth": 80 }],
"import/prefer-default-export": "off"
"import/prefer-default-export": "off",
"react/require-default-props": "off",
"no-restricted-syntax": "off",
"react/jsx-props-no-spreading": "off",
"react/button-has-type": "off"
}
}
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI 체크중..

on:
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: 레포지토리 체크아웃 중..
uses: actions/checkout@v2

- name: node 설치중..
uses: actions/setup-node@v2
with:
node-version: '20.2.0'

- name: yarn 설치중..
run: npm install -g yarn

- name: 종속성 설치중...
run: yarn install

- name: 빌드 중..
run: yarn build
69 changes: 69 additions & 0 deletions .pnp.cjs

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

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "src/app/globals.css",
"baseColor": "slate",
"cssVariables": false,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/util"
}
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
"@tanstack/react-query": "^5.51.1",
"@tanstack/react-query-devtools": "^5.51.1",
"axios": "^1.7.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.411.0",
"next": "14.2.4",
"react": "^18",
"react-dom": "^18",
"tailwind-variants": "^0.2.1"
"tailwind-merge": "^2.4.0",
"tailwind-variants": "^0.2.1",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.6.1",
Expand Down
6 changes: 5 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import { QueryProvider } from '@/lib';
import './globals.css';
import QueryProvider from '@/context/QueryProvider/QueryProvider';

const inter = Inter({ subsets: ['latin'] });

Expand All @@ -16,7 +18,9 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={inter.className}>
<QueryProvider>{children}</QueryProvider>
</body>
</html>
);
}
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useIsClient';
11 changes: 11 additions & 0 deletions src/hooks/useIsClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use client';

import { useSyncExternalStore } from 'react';

export function useIsClient() {
return useSyncExternalStore(
() => () => {},
() => true,
() => false,
);
}
46 changes: 46 additions & 0 deletions src/lib/AsyncBoundary/AsyncBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use client';

import { forwardRef } from 'react';
import { useQueryErrorResetBoundary } from '@tanstack/react-query';
import { chain } from '@/utils';
import { ErrorBoundary } from '../ErrorBoundary/ErrorBoundary';
import SSRSafeSuspense from '../SSRSafeSuspense/SSRSafeSuspense';
import type { StrictPropsWithChildren } from '@/types';
import type { ComponentProps, ComponentRef, Suspense } from 'react';

type ErrorBoundaryProps = Omit<ComponentProps<typeof ErrorBoundary>, 'renderFallback'>;
type SuspenseProps = Omit<ComponentProps<typeof Suspense>, 'fallback'>;

type AsyncBoundrayProps = StrictPropsWithChildren &
ErrorBoundaryProps &
SuspenseProps & {
errorFallback?: ComponentProps<typeof ErrorBoundary>['renderFallback'];
pendingFallback?: ComponentProps<typeof Suspense>['fallback'];
};

export const AsyncBoundary = forwardRef<ComponentRef<typeof ErrorBoundary>, AsyncBoundrayProps>(
({ errorFallback, pendingFallback, children, ...errorBoundaryProps }, ref) => {
return (
<ErrorBoundary ref={ref} renderFallback={errorFallback} {...errorBoundaryProps}>
<SSRSafeSuspense fallback={pendingFallback}>{children}</SSRSafeSuspense>
</ErrorBoundary>
);
},
);

AsyncBoundary.displayName = 'AsyncBoundary';

export const AsyncBoundaryWithQuery = forwardRef<ComponentRef<typeof ErrorBoundary>, AsyncBoundrayProps>(
(props, ref) => {
const { children, ...otherProps } = props;
const { reset } = useQueryErrorResetBoundary();

return (
<AsyncBoundary ref={ref} {...otherProps} onReset={chain(props.onReset, reset)}>
{children}
</AsyncBoundary>
);
},
);

AsyncBoundaryWithQuery.displayName = 'AsyncBoundaryWithQuery';
Loading

0 comments on commit 5148b39

Please sign in to comment.