diff --git a/.gitignore b/.gitignore index 0b50e408..2f755392 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ dist functions/lib/**/*.js functions/lib/**/*.js.map + +# Firebase cache +.firebase/ \ No newline at end of file diff --git a/docs.json b/docs.json index 9b5af91e..b2d092f7 100644 --- a/docs.json +++ b/docs.json @@ -48,6 +48,20 @@ } ] }, + { + "tab": "react", + "group": "Data Connect", + "pages": [ + { + "href": "/react/hooks/data-connect/useConnectQuery", + "title": "useConnectQuery" + }, + { + "href": "/react/hooks/data-connect/useConnectMutation", + "title": "useConnectMutation" + } + ] + }, { "tab": "react", "group": "Firestore", diff --git a/docs/react/hooks/data-connect/useConnectMutation.mdx b/docs/react/hooks/data-connect/useConnectMutation.mdx new file mode 100644 index 00000000..bcda15de --- /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 create, 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 "@tanstack-query-firebase/react"; +import { createMovieRef } from "@your-package-name/your-connector"; + +function Component() { + const { mutate, isPending, isSuccess, isError, error } = + useConnectMutation(createMovieRef); + + 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 */} + +
+
+ ); +} +``` diff --git a/docs/react/hooks/data-connect/useConnectQuery.mdx b/docs/react/hooks/data-connect/useConnectQuery.mdx new file mode 100644 index 00000000..05536469 --- /dev/null +++ b/docs/react/hooks/data-connect/useConnectQuery.mdx @@ -0,0 +1,42 @@ +--- +title: useConnectQuery +--- + +`useConnectQuery` is a hook designed to simplify data fetching and state management with Firebase Data Connect. +This hook integrates with [Firebase Data Connect](https://firebase.google.com/docs/data-connect), which leverages GraphQL to interact with a PostgreSQL database (via Cloud SQL) for secure, scalable data operations. +The hook simplifies the process of querying data from Firebase Data Connect and provides an easy-to-use interface to manage loading, success, and error states in your React application. + +## Features + +- Provides type-safe handling of queries based on the Firebase Data Connect schema. +- Simplifies data fetching using Firebase Data Connect. +- Automatically manages loading, success, and error states. +- Supports refetching data with integrated caching. + +## Usage + +```jsx +import { useConnectQuery } from "@tanstack-query-firebase/react"; +import { listMoviesQuery } from "@your-package-name/your-connector"; + +function Component() { + const { data, isPending, isSuccess, isError, error } = useConnectQuery( + listMoviesQuery() + ); + + if (isPending) return
Loading...
; + if (isError) return
Error: {error.message}
; + + return ( +
+ {isSuccess && ( + + )} +
+ ); +} +```