Skip to content

Commit

Permalink
feat: finish react query
Browse files Browse the repository at this point in the history
  • Loading branch information
laoriy committed Apr 20, 2024
1 parent 449d80d commit a4efa3b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions 5.react/7.react-query/src/Parallel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useQueries } from "@tanstack/react-query";
import axios from "axios";
import React from "react";

async function fetchTodos() {
return axios.get("/todos");
}
async function fetchPosts() {
return axios.get("/posts");
}

function Parralle() {
const result = useQueries({
queries: [
{ queryKey: ["anotherTodos"], queryFn: fetchTodos },
{
queryKey: ["anotherPosts"],
queryFn: fetchPosts,
},
],
});

return (
<div>
<pre>
{JSON.stringify(
result.map((v) => v.data),
null,
2
)}
</pre>
</div>
);
}

export default Parralle;
2 changes: 2 additions & 0 deletions 5.react/7.react-query/src/Todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState } from "react";
import "./todo.css";
import Footer from "./Footer";
import { useTodos } from "./hooks/useTodos";
import Parallel from "./Parallel";

function addTodo(todo) {
console.log(todo);
Expand Down Expand Up @@ -78,6 +79,7 @@ function Todo() {
))}
</ul>
<Footer />
<Parallel></Parallel>
</section>
);
}
Expand Down

0 comments on commit a4efa3b

Please sign in to comment.