frontend-opensource-project / use-react-hooks

React hoooooooks😎
https://frontend-opensource-project.github.io/use-react-hooks/
5 stars 0 forks source link

[URH-103] useDelayFlag 수정 및 문서 작성 #81

Closed bicochan closed 3 weeks ago

bicochan commented 1 month ago

👾 Pull Request

1️⃣ Spec

2️⃣ 변경 사항

3️⃣ 예시 코드

import { useEffect, useState } from 'react';
import { useDelayFlag } from '@frontend-opensource/use-react-hooks';

function App() {
  const [flag, setFlag] = useState(true);
  const delayFlag = useDelayFlag({ flag, delayTime: 3000 });

  // 1초 뒤에 flag를 업데이트하는 함수
  const updateFlagAsync = async () => {
    await new Promise((resolve) => setTimeout(resolve, 1000));
    setFlag(false);
  };

  useEffect(() => {
    updateFlagAsync();
  }, []);

  return (
    <div>
      {/* 1초 뒤에 flag 업데이트됨 */}
      {flag ? <p>Loading...</p> : <p>Loaded</p>}

      {/* 3초 뒤에 delayFlag 업데이트됨 */}
      {delayFlag ? <p>Delayed Loading...</p> : <p>Delayed Loaded</p>}
    </div>
  );
}

문서 스크린샷

localhost_3000_docs_hooks_useDelayFlag