- CommonJS
npm install dotenv
const dotenv = require("dotenv").config();
const apiKey = process.env.API_KEY;
- ModuleJS (ES6)
npm install dotenv
| // Important Notes | |
| queryFn: ApiServices.getLandingPage(query) // ❌ executes immediately | |
| queryFn: () => ApiServices.getLandingPage(query) // ✅ pass a function. / queryFn must be a function that returns a Promise | |
| // React Query will call it internally, handle await, and track isLoading, isError, data automatically | |
| // mutate fn | |
| mutationFn: async (payload) => { | |
| const res = await ApiServices.registerUserWithRoles(payload); // Or with extra logic: |
| // apis/APIs.js | |
| class ApiServices { | |
| async updateProfile(data) { | |
| try { | |
| const res = await api.put("/user/update-profile", data); | |
| return res?.data; | |
| } catch (error) { | |
| throw error.response?.data || error; | |
| } finally { | |
| console.log("updateProfile: FINALLY executed"); |
| import { useQuery, useSuspenseQuery } from "@tanstack/react-query"; | |
| import ApiServices from "../../apis/APIs.js"; | |
| // api has try, catch, finally | |
| class ApiServices { | |
| async getLandingPage(query = {}) { | |
| try { | |
| const response = await api.get(`/user/dashboard`, { | |
| params: query, | |
| }); |
| // Date Format Helper Functions | |
| const formatDate = (dateString, format = "dd/MM/yyyy") => { | |
| if (!dateString) return ""; // Handle empty date | |
| const date = new Date(dateString); | |
| if (isNaN(date.getTime())) return "Invalid Date"; // Check if date is valid | |
| const day = String(date.getDate()).padStart(2, "0"); | |
| const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are zero-based | |
| const year = date.getFullYear(); |
| /* eslint-disable react/prop-types */ | |
| import { AnimatePresence, motion } from "motion/react"; | |
| import { Check, Copy, X } from "lucide-react"; | |
| import { toast } from "react-toastify"; | |
| import { useState } from "react"; | |
| const proposals = { | |
| quote_id: "Q300008826023", | |
| quote_no: "QT/25/6200028116", | |
| proposal_no: "PR/25/6200002447", | |
| proposal_id: "PR300001577841", |
| import mongoose from "mongoose"; | |
| const { Schema } = mongoose; | |
| const claimSchema = new Schema({ | |
| sNo: { type: Number, unique: true }, | |
| date: { type: Date }, | |
| companyName: { type: String}, | |
| claimType: { type: String }, | |
| policyNo: { type: String }, | |
| insuredName: { type: String }, |
| function MasterView() { | |
| const [allDetailsData, setAllDetailsData] = useState([]); | |
| const handleNumericInput = (e) => { | |
| const input = e.target.innerText; | |
| const numericInput = input.replace(/[^\d.]/g, ''); // Remove any non-numeric characters | |
| if (input !== numericInput) { | |
| e.target.innerText = numericInput; // Update the contentEditable element with numeric value | |
| } |
| import { useState } from 'react'; | |
| const App = () => { | |
| const [albums, setAlbums] = useState([ | |
| { userId: 1, title: 'Album', id: 1 }, | |
| { userId: 1, title: 'omnis laborum odio', id: 2 }, | |
| { userId: 1, title: 'omnis laborum odio 2', id: 3 }, | |
| { userId: 2, title: 'aque aut omnis a', id: 4 }, | |
| { userId: 2, title: 'aque aut omnis a laborum odio', id: 5 }, | |
| { userId: 3, title: 'omnis laque aut omnis', id: 6 }, | |
| ]); |
| import React, { useState } from 'react'; | |
| function AddTerminator() { | |
| const [terminatedate, setTerminateDate] = useState(""); | |
| const [dateInput, setDateInput] = useState(""); | |
| const convertDateFormat = (dateStr) => { | |
| const [year, month, day] = dateStr.split('-'); | |
| return `${day}-${month}-${year}`; | |
| }; |