-
Notifications
You must be signed in to change notification settings - Fork 0
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
apply swr for list page #34
base: main
Are you sure you want to change the base?
Changes from 3 commits
6de73e3
352f26b
69ba4e1
eca60ea
1fd7882
f33b221
5baa0ca
1ad7029
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import "firebase/firestore"; | ||
import { News } from "../../models/news"; | ||
import useSWR from 'swr'; | ||
import { RetrieveNews } from "../../firestore/news/retrieveNews"; | ||
|
||
export function useNewListData() { | ||
const { data, error } = useSWR("useNewListData", async () => { | ||
return await RetrieveNews(); | ||
}); | ||
|
||
return { | ||
newsList: data as News[], | ||
isError: !!error, | ||
isLoading: !data && !error, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import "firebase/firestore"; | ||
import { News } from "../../models/news"; | ||
import useSWR from 'swr'; | ||
import { RetrieveNewsById } from "../../firestore/news/retrieveNewsById"; | ||
|
||
export function useRetrieveNewsDataById(idNews:string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @duoctvd |
||
|
||
const { data, error } = useSWR("useRetrieveNewsDataById", async () => { | ||
return await RetrieveNewsById(idNews); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @duoctvd There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@bit-thuynt: Em đang dùng thế này để truyền newsId qua hooks, em đang cảm thấy nó k đc truyền qua mỗi lần request (vì còn còn dùng trong getServerSideProps), nên lúc thì nó qua đc data lúc thì nó là undifie There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @duoctvd Khi nào news id có giá trị thì mới gọi get.
|
||
}); | ||
|
||
return { | ||
news: data as News, | ||
isError: !!error, | ||
isLoading: !data && !error, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@duoctvd
Thêm kiểu trả về cho function