This file contains 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
/** | |
* ✅ Topic: Unnecessary useMemo() on props 🧐 | |
* 📨 For training contact: sifathaque6@gmail.com 💬 | |
*/ | |
const ChildrenMemo = React.memo(Children) | |
const Parent = () => { | |
const value = useMemo(() => ({value})); | |
This file contains 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
// Problem | |
function App() { | |
const [scrollY, setScrollY] = useState(0); | |
function handleScroll(event) { | |
setScrollY(...); | |
} | |
return ( |
This file contains 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
/** | |
* ✅ Topic: Create Map with timer in javascript 🎉 | |
* 📨 For personalized training contact: sifathaque6@gmail.com 💬 | |
*/ | |
class MapWithTimer extends Map { | |
#timerRefMap = new Map(); | |
// time in milliseconds | |
set(key, value, time = 1000) { |
This file contains 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
/** | |
* ✅ Topic: Create Strange Object in javascript 🧐 | |
* 📨 For personalized training contact: sifathaque6@gmail.com 💬 | |
*/ | |
function createStrageObject() { | |
return new Proxy( | |
{}, | |
{ | |
get(_, prop) { |
This file contains 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
/** | |
* ✅ Topic: Proxy in javascript | |
* 📨 For personalized training contact: sifathaque6@gmail.com 💬 | |
*/ | |
const arrayHandler = { | |
get: function (arr, property) { | |
if (property < 0) { | |
return arr[arr.length + parseInt(property)]; |
This file contains 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
/** | |
* ✅ Topic: Using Promise.race() to implement request timeout 🎉 | |
* ⭐️ Email: 📨 sifathaque6@gmail.com 👈 | |
*/ | |
const data = Promise.race([ | |
fetch('https://jsonplaceholder.typicode.com/todos/1'), | |
new Promise((resolve, reject) => { | |
// Reject after 5 seconds | |
setTimeout(() => reject(new Error('Request timed out')), 5000); |
This file contains 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
/** | |
* ✅ Topic: Promise.allSettled in javascript 🎉 | |
* ⭐️ Email: 📨 sifathaque6@gmail.com 👈 | |
*/ | |
const promises = [ | |
fetch('/quit-social-media'), | |
fetch('/wake-up-early'), | |
fetch('/go-to-bed-early') |
This file contains 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
/** | |
* ✅ Topic: async/await coding challenge in javascript 🎉 | |
* ⭐️ Email: 📨 sifathaque6@gmail.com 👈 | |
*/ | |
// ✅ Rewrite the following code using async/await | |
function getUsersData() { | |
fetch('/users') |
This file contains 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
/** | |
* ✅ Topic: Some interesting facts about (undefined and null) in javascript 🎉 | |
* ⭐️ Email: 📨 sifathaque6@gmail.com 👈 | |
*/ | |
// ✅ JSON.stringify() converts undefined to null if used as an array value | |
const str = JSON.stringify([null, undefined]); | |
// ➡️ str = [null,null] 😮 (undefined is converted to null) |
This file contains 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
/** | |
* ✅ Topic: Intl.RelativeTimeFormat in javascript 🎉 | |
* ⭐️ Email: 📨 sifathaque6@gmail.com 👈 | |
*/ | |
const rtf1En = new Intl.RelativeTimeFormat('en'); | |
console.log(rtf1En.format(5, 'year')); // in 5 years | |
console.log(rtf1En.format(-5, 'year')); // 5 years ago |
NewerOlder