-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
queries not returning as objects, stuck
- Loading branch information
Showing
7 changed files
with
89 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const fetchOne = async ({ queryKey }) => { | ||
const id = queryKey[1]; | ||
const apiRes = await fetch(`http://localhost:3000/api/getOne/?id=${id}`); | ||
|
||
if (!apiRes.ok) { | ||
throw new Error(`getOne/${id} fetch not ok`); | ||
} | ||
|
||
return apiRes.json(); | ||
}; | ||
|
||
export default fetchOne; |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const getAll = async (queryKey) => { | ||
const id = queryKey[1]; | ||
const apiRes = await fetch(`http://localhost:3000/api/getall/?id=${id}`); | ||
|
||
if (!apiRes.ok) { | ||
throw new Error(`getAll fetch not ok`); | ||
} | ||
|
||
return apiRes.json(); | ||
}; | ||
|
||
export default getAll; |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import getAll from "../bin/getAll.js"; | ||
import { useParams } from "react-router-dom"; | ||
|
||
const Details = () => { | ||
const { data } = useParams(); | ||
|
||
const results = useQuery({ queryKey: [data], getAll }); | ||
|
||
if (results.isLoading) { | ||
return ( | ||
<div className="loading-pane"> | ||
<h2 className="loader">🌀</h2> | ||
</div> | ||
); | ||
} | ||
|
||
const stuff = results; | ||
|
||
console.log(stuff); | ||
|
||
return ( | ||
<div> | ||
{stuff.data.map((id) => ( | ||
<div key={id}>{id}</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
export default Details; |