Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@aspida/react-query
Advanced tools
Readme
Using npm:
$ npm install @aspida/react-query @aspida/axios react-query axios
# $ npm install @aspida/react-query @aspida/fetch react-query
# $ npm install @aspida/react-query @aspida/node-fetch react-query node-fetch
Using Yarn:
$ yarn add @aspida/react-query @aspida/axios react-query axios
# $ yarn add @aspida/react-query @aspida/fetch react-query
# $ yarn add @aspida/react-query @aspida/node-fetch react-query node-fetch
src/index.ts
import { useQueryClient, useMutation, QueryClient, QueryClientProvider } from "react-query"
import { useAspidaQuery } from "@aspida/react-query"
import aspida from "@aspida/axios" // "@aspida/fetch", "@aspida/node-fetch"
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 { useMutation, QueryClient, QueryClientProvider } from "react-query"
import { useAspidaQuery } from "@aspida/react-query"
import aspida from "@aspida/axios" // "@aspida/fetch", "@aspida/node-fetch"
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 { useMutation, QueryClient, QueryClientProvider } from "react-query"
import { useAspidaQuery } from "@aspida/react-query"
import aspida from "@aspida/axios" // "@aspida/fetch", "@aspida/node-fetch"
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
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
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).