This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//---------- 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, () => { }, () => { }] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//----------------------- 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//----------------------- 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |