Skip to content

Instantly share code, notes, and snippets.

View sandy088's full-sized avatar
👋
Lets Connect

Sandeep Singh sandy088

👋
Lets Connect
View GitHub Profile
@sandy088
sandy088 / use-loal-storage.js
Created April 13, 2024 04:54
use-local-storage (custom hook)
//---------- use-local-storage.js -------------------
import { useState } from "react"
//edge case , check if window is not undefined, otherwise app will break:
const isBrowser = typeof window !== undefined
export const useLocalStorage = (key, initialValue) => {
//handling edge case - where window is not presend!!
if (!isBrowser) return [initialValue, () => { }, () => { }]
@sandy088
sandy088 / useCustomMemo.js
Created April 8, 2024 09:51
useMemo() Hook Pollyfill
//----------------------- useCustomMemo() --------------------------
import { useRef, useEffect } from "react"
const checkChanges = (prevDeps, deps) => {
if(prevDeps === null) return false
if (prevDeps?.length !== deps.length) return false;
for (let i = 0; i < deps.length; i++) {
if (prevDeps[i] !== deps[i]) return false;
@sandy088
sandy088 / gist:7224228ee7d7ba9c5471773699ee748f
Created April 8, 2024 06:44
useMemo() Hook Pollyfill - useCustomMemo()
//----------------------- useCustomMemo() --------------------------
import { useRef, useEffect } from "react"
const checkChanges = (prevDeps, deps) => {
if(prevDeps === null) return false
if (prevDeps?.length !== deps.length) return false;
for (let i = 0; i < deps.length; i++) {
if (prevDeps[i] !== deps[i]) return false;
@sandy088
sandy088 / try.js
Created August 12, 2023 05:59
How to use fs modukle in javascript
const fs = require('fs'); // We're using the 'fs' module to work with files.
// Writing to the file
fs.writeFileSync('notes.txt', 'Hello, world!');
// This line creates a new file named 'notes.txt' and writes 'Hello, world!' inside it.
// Reading from the file
const content = fs.readFileSync('notes.txt', 'utf-8');
// Here, we're reading the contents of 'notes.txt' and storing it in the 'content' variable.