Skip to content

Instantly share code, notes, and snippets.

View sifat009's full-sized avatar
🎯
Focusing

sifat haque sifat009

🎯
Focusing
View GitHub Profile
@sifat009
sifat009 / usememo-right-way.jsx
Created March 3, 2024 11:43
useMemo the right way
/**
* ✅ Topic: Unnecessary useMemo() on props 🧐
* 📨 For training contact: sifathaque6@gmail.com 💬
*/
const ChildrenMemo = React.memo(Children)
const Parent = () => {
const value = useMemo(() => ({value}));
@sifat009
sifat009 / prevent-re-render.js
Created February 25, 2024 17:16
pevent unnecessary re-render in react.js
// Problem
function App() {
const [scrollY, setScrollY] = useState(0);
function handleScroll(event) {
setScrollY(...);
}
return (
@sifat009
sifat009 / mapWithTimer.js
Created June 11, 2023 16:51
Map with timer to delete existing data after a certain time period
/**
* ✅ 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) {
@sifat009
sifat009 / strange-object.js
Created May 21, 2023 15:14
create strange object in javascript
/**
* ✅ Topic: Create Strange Object in javascript 🧐
* 📨 For personalized training contact: sifathaque6@gmail.com 💬
*/
function createStrageObject() {
return new Proxy(
{},
{
get(_, prop) {
@sifat009
sifat009 / use_of_proxy.js
Created April 9, 2023 15:27
Proxy in javascript
/**
* ✅ 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)];
@sifat009
sifat009 / request-timeout.js
Created March 5, 2023 14:15
Using Promise.race() to implement request timeou
/**
* ✅ 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);
@sifat009
sifat009 / promise-allsettled.js
Created February 12, 2023 15:47
promise all settled javascript
/**
* ✅ Topic: Promise.allSettled in javascript 🎉
* ⭐️ Email: 📨 sifathaque6@gmail.com 👈
*/
const promises = [
fetch('/quit-social-media'),
fetch('/wake-up-early'),
fetch('/go-to-bed-early')
@sifat009
sifat009 / async-await-coding-challenge.js
Last active January 1, 2023 13:42
async await coding challenge
/**
* ✅ Topic: async/await coding challenge in javascript 🎉
* ⭐️ Email: 📨 sifathaque6@gmail.com 👈
*/
// ✅ Rewrite the following code using async/await
function getUsersData() {
fetch('/users')
@sifat009
sifat009 / nullVsUndefined.js
Created December 4, 2022 16:19
Some interesting facts about (undefined and null) in javascript
/**
* ✅ 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)
@sifat009
sifat009 / Intl.RelativeTimeFormat.js
Created November 13, 2022 13:15
Intl.RelativeTimeFormat in javascript
/**
* ✅ 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