Download wp-calypso/client/data/viewers/use-remove-viewer-mutation.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 740 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/viewers/use-remove-viewer-mutation.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/data/viewers/use-remove-viewer-mutation.js
-
curl -L -o use-remove-viewer-mutation.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/data/viewers/use-remove-viewer-mutation.js
740 Bytes
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | |
| import { useCallback } from 'react'; | |
| import wp from 'calypso/lib/wp'; | |
| function useRemoveViewer() { | |
| const queryClient = useQueryClient(); | |
| const mutation = useMutation( { | |
| mutationFn: ( { siteId, viewerId } ) => { | |
| return wp.req.post( `/sites/${ siteId }/viewers/${ viewerId }/delete` ); | |
| }, | |
| onSuccess( data, variables ) { | |
| const { siteId } = variables; | |
| queryClient.invalidateQueries( { | |
| queryKey: [ 'viewers', siteId ], | |
| } ); | |
| }, | |
| } ); | |
| const { mutate } = mutation; | |
| const removeViewer = useCallback( | |
| ( siteId, viewerId ) => mutate( { siteId, viewerId } ), | |
| [ mutate ] | |
| ); | |
| return { removeViewer, ...mutation }; | |
| } | |
| export default useRemoveViewer; | |