diff --git a/docs.json b/docs.json index 955232b..b2d092f 100644 --- a/docs.json +++ b/docs.json @@ -57,7 +57,7 @@ "title": "useConnectQuery" }, { - "href": "/react/hooks/data-connect/useConnectQuery", + "href": "/react/hooks/data-connect/useConnectMutation", "title": "useConnectMutation" } ] diff --git a/docs/react/hooks/data-connect/useConnectMutation.mdx b/docs/react/hooks/data-connect/useConnectMutation.mdx new file mode 100644 index 0000000..969ca65 --- /dev/null +++ b/docs/react/hooks/data-connect/useConnectMutation.mdx @@ -0,0 +1,49 @@ +--- +title: useConnectMutation +--- + +`useConnectMutation` is a hook designed to simplify handling mutations (creating, updating, deleting) with Firebase Data Connect. +This hook integrates with [Firebase Data Connect](https://firebase.google.com/docs/data-connect), which uses GraphQL to interact with a PostgreSQL database (via Cloud SQL) for secure, scalable data operations. +The hook manages the mutation process and provides an easy-to-use interface to manage loading, success, and error states in your React application. + +## Features + +- Simplifies mutation handling for creatt, update, and delete operations using Firebase Data Connect. +- Provides type-safe handling of mutations based on your Firebase Data Connect schema. +- Automatically manages loading, success, and error states for mutations. +- Supports optimistic updates and caching to improve user experience and performance. + +## Usage + +```jsx +import { useConnectQuery } from "./useConnectQuery"; +import { listMoviesQuery } from "@/your-package-name/your-connector"; + +function Component() { + const { mutate, isPending, isSuccess, isError, error } = + useConnectMutation(createMovieMutation); + + const handleSubmit = async (movieData) => { + try { + await mutate(movieData); + } catch (err) { + console.error("Failed to add movie:", err); + } + }; + + if (isPending) return
Adding movie...
; + if (isError) return
Error: {error.message}
; + + return ( +
+ {isSuccess &&
Movie added successfully!
} +
handleSubmit(e.target)}> + {/* Form fields for movie data */} + +
+
+ ); +} +```