Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(react): useBlockPromiseMultipleClick 훅의 비교 예시에 debounce 버튼 추가 완료 #103

Closed
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
24 changes: 22 additions & 2 deletions docs/docs/react/hooks/useBlockPromiseMultipleClick.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { useBlockPromiseMultipleClick } from '@modern-kit/react';
import { debounce } from 'lodash-es';

# useBlockPromiseMultipleClick

Expand Down Expand Up @@ -71,27 +72,46 @@ const Example = () => {
export const Example = () => {
const [blockingCount, setBlockingCount] = useState(1);
const [nonBlockingCount, setNonBlockingCount] = useState(1);
const [debouncingCount, setDebouncingCount] = useState(1);
const [value, setValue] = useState(null);
const [isApiLoading, setIsApiLoading] = useState(false)
const { isLoading, blockMultipleClick } = useBlockPromiseMultipleClick();

const fetchApi = async () => {
const res = await fetch(
`https://jsonplaceholder.typicode.com/todos/${blockingCount}`
).then((response) => response.json());
setValue(res);
setBlockingCount(blockingCount + 1);
};

const debouncedFetchApi = debounce(async () => {
setIsApiLoading(true)
setDebouncingCount(debouncingCount + 1);
const res = await fetch(
`https://jsonplaceholder.typicode.com/todos/${blockingCount}`
).then((response) => response.json());
setValue(res);
setIsApiLoading(false);
}, 1000);

const handleClick = () => {
setNonBlockingCount(nonBlockingCount + 1);
blockMultipleClick(fetchApi);
};

return (
<div>
<button onClick={handleClick}>버튼 클릭</button>
<div style={{ display: "flex" }}>
<button onClick={handleClick}>버튼 클릭</button>
<div style={{ width: "50px" }} />
<button onClick={debouncedFetchApi}>debounce 버튼 클릭</button>
</div>
<div>
<p>BlockingCount: {blockingCount}</p>
<p>NonBlockingCount: {nonBlockingCount}</p>
</div>
{isLoading ? <p>로딩중</p> : <p>{value?.title}</p>}
{isLoading || isApiLoading ? <p>로딩중</p> : <p>{value?.title}</p>}
</div>
);
};
Expand Down
Loading