Download wp-calypso/client/sites/marketing/sharing/use-sharing-buttons-query.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 958 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/sites/marketing/sharing/use-sharing-buttons-query.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/sites/marketing/sharing/use-sharing-buttons-query.js
-
curl -L -o use-sharing-buttons-query.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/sites/marketing/sharing/use-sharing-buttons-query.js
958 Bytes
| import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | |
| import { useCallback } from 'react'; | |
| import wpcom from 'calypso/lib/wp'; | |
| export function useSharingButtonsQuery( siteId ) { | |
| return useQuery( { | |
| queryKey: [ 'sharing-buttons', siteId ], | |
| queryFn: () => | |
| wpcom.req | |
| .get( `/sites/${ siteId }/sharing-buttons` ) | |
| .then( ( data ) => data.sharing_buttons ), | |
| enabled: !! siteId, | |
| } ); | |
| } | |
| export function useSaveSharingButtonsMutation( siteId ) { | |
| const queryClient = useQueryClient(); | |
| const mutation = useMutation( { | |
| mutationFn: ( { buttons } ) => | |
| wpcom.req.post( `/sites/${ siteId }/sharing-buttons`, { sharing_buttons: buttons } ), | |
| onSuccess( data ) { | |
| queryClient.setQueryData( [ 'sharing-buttons', siteId ], data.updated ); | |
| }, | |
| } ); | |
| const { mutate } = mutation; | |
| const saveSharingButtons = useCallback( ( buttons ) => mutate( { buttons } ), [ mutate ] ); | |
| return { ...mutation, saveSharingButtons }; | |
| } | |