Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add query function context (#1261)
- Loading branch information
Showing
24 changed files
with
191 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { useQuery } from "react-query"; | ||
import axios from "axios"; | ||
|
||
const getPostById = async (_, postId) => { | ||
const getPostById = async (postId) => { | ||
const { data } = await axios.get( | ||
`https://jsonplaceholder.typicode.com/posts/${postId}` | ||
); | ||
return data; | ||
}; | ||
|
||
export default function usePost(postId) { | ||
return useQuery(["post", postId], getPostById); | ||
return useQuery(["post", postId], () => getPostById(postId)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import ky from 'ky-universal' | ||
import { useQuery } from 'react-query' | ||
|
||
const fetchPosts = async (_, limit) => { | ||
const offset = limit ?? 10 | ||
|
||
const fetchPosts = async (limit = 10) => { | ||
const parsed = await ky('https://jsonplaceholder.typicode.com/posts').json() | ||
const result = parsed.filter(x => x.id <= offset) | ||
const result = parsed.filter(x => x.id <= limit) | ||
return result | ||
} | ||
|
||
const usePosts = limit => { | ||
return useQuery(['posts', limit], fetchPosts) | ||
return useQuery(['posts', limit], () => fetchPosts(limit)) | ||
} | ||
|
||
export { usePosts, fetchPosts } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.