0.0.12 • Published 5 months ago
@rustedcompiler/frappe-hooks v0.0.12
@rustedcompiler/frappe-hooks
A lightweight React.js wrapper for the Frappe REST API, enabling easy integration with Frappe backend in your React applications.
✅ Features
- Easy login with username/password or API key/secret
- Hooks for standard REST operations (GET, POST, PUT, DELETE)
- File upload/download support (coming soon)
📦 Installation
npm install @rustedcompiler/frappe-hooksInitialization
Wrap your application with the FrappeProvider to initialize the client globally:
import { FrappeProvider } from '@rustedcompiler/frappe-hooks';
function App({ children }) {
return (
<FrappeProvider
options={{
baseURL: 'https://asa.aksla.com',
// Optional if using token authentication
token: 'api_key:api_secret',
}}
>
<body>{children}</body>
</FrappeProvider>
);
}Example Usage
Getting all Documents
import {useDocuments , useDocument } from "@rustedcompiler/frappe-hooks"
// Get all documents of a specific DocType
import { useDocuments } from '@rustedcompiler/frappe-hooks';
const { data } = useDocuments({
docType: docType,
enabled: true,
});Querying Data
// query
const { data } = useDocuments({
docType: docType,
query: {
},
enabled: true,
filters: [
{
query: 'email',
operand: 'EQ',
value: 'email@gmail.com',
}
],
});By default all filters will be using AND, In Order to use OR
const { data } = useDocuments({
docType: docType,
query: {
},
enabled: true,
filters: [
{
query: 'email',
operand: 'EQ',
value: 'email@gmail.com',
},
{
query: 'email',
operand: 'EQ',
value: 'email@gmail.com',
}
],
isOR:true
});Fetching a Single Document
// Get a single document
import { useDocument } from '@rustedcompiler/frappe-hooks';
const { data } = useDocument(docType, documentId); // Update a document
const { updateDocument } = useDocument();
await updateDocument(docType, documentId, {
score: 0,
});// Delete a document
const { deleteDocument } = useDocument();
await deleteDocument(docType, documentId);Getting the Current User
import { useEffect } from 'react';
import { useAuth } from '@rustedcompiler/frappe-hooks';
function MyComponent() {
const { loginWithPassword, currentUser , logout } = useAuth();
useEffect(() => {
console.log(currentUser);
}, [currentUser]);
}0.0.12
5 months ago
0.0.11
5 months ago
0.0.10
5 months ago
0.0.9
6 months ago
0.0.8
6 months ago
0.0.7
6 months ago
0.0.6
6 months ago
0.0.5
6 months ago
0.0.4-beta.11
6 months ago
0.0.4-beta.10
6 months ago
0.0.4-beta.9
6 months ago
0.0.4-beta.8
6 months ago
0.0.4-beta.7
6 months ago
0.0.4-beta.6
6 months ago
0.0.4-beta.5
6 months ago
0.0.4-beta.4
6 months ago
0.0.4-beta.3
6 months ago
0.0.4-beta.2
6 months ago
0.0.4-beta.1
6 months ago
0.0.4
6 months ago
0.0.3
6 months ago
0.0.2-beta.6
6 months ago
0.0.2-beta.5
6 months ago
0.0.2-beta.4
6 months ago
0.0.2-beta.3
6 months ago
0.0.2-beta.2
6 months ago
0.0.2-beta.1
6 months ago
0.0.2
6 months ago
0.0.1
6 months ago