0.0.12 • Published 12 months ago

@rustedcompiler/frappe-hooks v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

@rustedcompiler/frappe-hooks

npm

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-hooks

Initialization

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

12 months ago

0.0.11

12 months ago

0.0.10

12 months ago

0.0.9

12 months ago

0.0.8

12 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4-beta.11

12 months ago

0.0.4-beta.10

12 months ago

0.0.4-beta.9

12 months ago

0.0.4-beta.8

12 months ago

0.0.4-beta.7

12 months ago

0.0.4-beta.6

12 months ago

0.0.4-beta.5

12 months ago

0.0.4-beta.4

12 months ago

0.0.4-beta.3

12 months ago

0.0.4-beta.2

12 months ago

0.0.4-beta.1

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2-beta.6

12 months ago

0.0.2-beta.5

12 months ago

0.0.2-beta.4

12 months ago

0.0.2-beta.3

12 months ago

0.0.2-beta.2

12 months ago

0.0.2-beta.1

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago