Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@aspida/react-query
Advanced tools
Readme
Using npm:
$ npm install aspida @aspida/react-query @aspida/axios react-query axios
# $ npm install aspida @aspida/react-query @aspida/fetch react-query
# $ npm install aspida @aspida/react-query @aspida/node-fetch react-query node-fetch
Using Yarn:
$ yarn add aspida @aspida/react-query @aspida/axios react-query axios
# $ yarn add aspida @aspida/react-query @aspida/fetch react-query
# $ yarn add aspida @aspida/react-query @aspida/node-fetch react-query node-fetch
src/index.ts
import aspida from "@aspida/axios"; // "@aspida/fetch", "@aspida/node-fetch"
import { useAspidaQuery } from "@aspida/react-query";
import { QueryClient, QueryClientProvider, useMutation, useQueryClient } from "react-query";
import api from "../api/$api";
const client = api(aspida());
const queryClient = new QueryClient();
function App() {
return (
// Provide the client to your App
<QueryClientProvider client={queryClient}>
<Todos />
</QueryClientProvider>
);
}
function postTodo(body: { id: number; title: string }) {
return client.todos.$post({ body });
}
function Todos() {
// Access the client
const queryClient = useQueryClient();
// Queries
const query = useAspidaQuery(client.todos, { query: { limit: 10 } });
// Mutations
const mutation = useMutation(postTodo, {
onSuccess: () => {
// Invalidate and refetch
queryClient.invalidateQueries(client.todos.$path({ query: { limit: 10 } }));
},
});
return (
<div>
<ul>
{query.data.map(todo => (
<li key={todo.id}>{todo.title}</li>
))}
</ul>
<button
onClick={() => {
mutation.mutate({
id: Date.now(),
title: "Do Laundry",
});
}}
>
Add Todo
</button>
</div>
);
}
render(<App />, document.getElementById("root"));
src/index.ts
import aspida from "@aspida/axios"; // "@aspida/fetch", "@aspida/node-fetch"
import { useAspidaQuery } from "@aspida/react-query";
import { QueryClient, QueryClientProvider } from "react-query";
import api from "../api/$api";
const client = api(aspida());
const queryClient = new QueryClient();
function App() {
return (
<QueryClientProvider client={queryClient}>
<Profile />
</QueryClientProvider>
);
}
function Profile() {
const { data, error } = useAspidaQuery(client.user._userId(123), "get", {
query: { name: "mario" },
});
if (error) return <div>failed to load</div>;
if (!data) return <div>loading...</div>;
return (
<>
<div>Status: {data.status}</div>
<div>Headers: {JSON.stringify(data.headers)}</div>
<div>Name: {data.body.name}</div>
</>
);
}
render(<App />, document.getElementById("root"));
useAspidaQuery(client.user._userId(123), { query })
is an alias of useAspidaQuery(client.user._userId(123), "$get", { query })
src/index.ts
import aspida from "@aspida/axios"; // "@aspida/fetch", "@aspida/node-fetch"
import { useAspidaQuery } from "@aspida/react-query";
import { QueryClient, QueryClientProvider } from "react-query";
import api from "../api/$api";
const client = api(aspida());
const queryClient = new QueryClient();
function App() {
return (
<QueryClientProvider client={queryClient}>
<Profile />
</QueryClientProvider>
);
}
function Profile() {
const { data, error } = useAspidaQuery(client.user._userId(123), {
query: { name: "mario" },
refetchOnMount: true,
initialData: { name: "anonymous" },
});
if (error) return <div>failed to load</div>;
return <div>hello {data.name}!</div>;
}
render(<App />, document.getElementById("root"));
@aspida/react-query is licensed under a MIT License.
FAQs
React Query wrapper for aspida
The npm package @aspida/react-query receives a total of 179 weekly downloads. As such, @aspida/react-query popularity was classified as not popular.
We found that @aspida/react-query demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.