bsky-app/src/state/queries/like.ts
Eric Bailey 45d354cd0c
[Session] Add useAgent hook and replace (#3706)
* Hook it up

* Memoize getAgent method

* Use one shared reference

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2024-04-25 22:29:05 +01:00

22 lines
541 B
TypeScript

import {useMutation} from '@tanstack/react-query'
import {useAgent} from '#/state/session'
export function useLikeMutation() {
const {getAgent} = useAgent()
return useMutation({
mutationFn: async ({uri, cid}: {uri: string; cid: string}) => {
const res = await getAgent().like(uri, cid)
return {uri: res.uri}
},
})
}
export function useUnlikeMutation() {
const {getAgent} = useAgent()
return useMutation({
mutationFn: async ({uri}: {uri: string}) => {
await getAgent().deleteLike(uri)
},
})
}