The `frappe-react-sdk` is a JavaScript library providing a collection of React hooks designed to simplify interaction with a Frappe Framework backend. It offers abstractions for common tasks such as user authentication (cookie-based or token-based), comprehensive database operations (fetching single documents, lists, counts, creating, updating, and deleting records), file uploads with progress tracking, and generic API calls to whitelisted backend functions. The current stable version is `1.14.0`. The library demonstrates an active release cadence, with updates typically every few weeks addressing bug fixes, dependency updates, and feature enhancements. Under the hood, it leverages `frappe-js-sdk` for Frappe API communication and `SWR` for efficient data fetching, caching, and automatic revalidation, providing a fast and reactive UI experience by default.
npm install frappe-react-sdkVerified import paths — ran on the pinned version, not inferred.
Demonstrates the basic setup using `FrappeProvider` and a simple authentication flow with `useFrappeAuth`.
Review Axios v1 migration guide and adjust API call parameters, headers, and error handling as necessary. Test all API interactions thoroughly.
Thoroughly test existing functionality after upgrading. Pay attention to data fetching, caching behavior, and any custom Axios configurations that might be affected by the dependency bumps.
Always provide the full URL to your Frappe server: `<FrappeProvider url='https://your-frappe-server.com'>`.
Pass the `token` or `enableAuth` props to `FrappeProvider` and manage the token lifecycle (e.g., `<FrappeProvider token={myAuthToken}>` or `<FrappeProvider enableAuth={true} />` and then use `frappe.setAuthToken`).Consult the SWR documentation regarding cache invalidation, revalidation, and API options when encountering unexpected data behavior or performance issues.
Set the `url` prop on `FrappeProvider` to the correct address of your Frappe backend: `<FrappeProvider url="https://your-frappe-server.com">`.
Use ES module import syntax: `import { FrappeProvider } from 'frappe-react-sdk';`Ensure the user is logged in via `useFrappeAuth().login()`, or if using token-based authentication, verify that the `token` prop is correctly passed to `FrappeProvider` and is valid.
Implement robust error handling and loading states. Check the network tab for the exact API response. Ensure optional chaining (`data?.value`) is used when accessing potentially undefined properties.