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

tanstack query도입 #5

Open
Dragonite-Lee opened this issue Mar 14, 2024 · 0 comments
Open

tanstack query도입 #5

Dragonite-Lee opened this issue Mar 14, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@Dragonite-Lee
Copy link
Contributor

tanstack query로 서버 데이터 관리시작
/services -> api통신을 위한 코드 작성
/components/{각각 해당되는 폴더}/query.js -> tanstack query 코드 작성
예시)

  1. api코드
    export const getAdMainNotice = async () =>{
    const data = await axios.get('/notice?_limit=8').then((res) => res.data);
    return data;
    }
  2. query코드
    export const useAdMainNoticeQuery = () => {
    const { data, isLoading } = useQuery(['/admin/main/notice'],() =>
    getAdMainNotice()
    );
    return {
    noticeData: data,
    isLoading
    }
    }
    3, 사용
    const { noticeData, isLoading } = useAdMainNoticeQuery()
@Dragonite-Lee Dragonite-Lee added the documentation Improvements or additions to documentation label Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant