Skip to content

Instantly share code, notes, and snippets.

View AsbDaryaee's full-sized avatar

Amir H. Moayeri AsbDaryaee

View GitHub Profile
@AsbDaryaee
AsbDaryaee / validator.ts
Last active November 3, 2024 11:54
a simple, framework-agnostic TypeScript form validator
type ValidatorFunction = (value: string) => string | null;
interface FormField {
value: string;
validators: ValidatorFunction[];
}
type Form = {
[key: string]: FormField;
};
@AsbDaryaee
AsbDaryaee / useSkipFirstRenderUseEffect.ts
Created October 25, 2024 17:25
React useEffect Hook that Skips First Render
import { useEffect, useRef } from 'react';
function useSkipFirstRenderUseEffect(callback: () => void, dependencies: [any]) {
const firstRenderRef = useRef(true);
useEffect(() => {
if (firstRenderRef.current) {
firstRenderRef.current = false;
return;
}
@AsbDaryaee
AsbDaryaee / Pagination.jsx
Last active October 14, 2024 19:41
Basic React Pagination Component + Tailwind CSS
import { useState, useEffect } from "react";
export default function Pagination ({
totalPages,
currentPage,
handlePageChange,
text,
className = "custom-class",
pageLimit = 10, // number of pages to show at a time
}) {