Skip to content

Instantly share code, notes, and snippets.

@itshimashis
itshimashis / useIntervaledPoll.jsx
Last active February 8, 2024 19:21
custom hook that does backEnd Polling every 5 seconds
import React from "react";
import { useState,useEffect } from "react";
let i=0;
function useTodos(n){
const [todos, setTodos] = useState([]);
const [loadStatus,setStatus]=useState(true);
useEffect(() => {
const Value=setInterval(()=>{
fetch("https://sum-server.100xdevs.com/todos")
.then(async (res) => {
@itshimashis
itshimashis / context-api.jsx
Created February 2, 2024 12:04
This is to understand Prop Drilling and context Api with useContext
import { createContext, useContext, useState } from "react";
// Create a single context for both name and address
const UserContext = createContext();
function App() {
const [state1,update1] = useState("himashis");
const [state2,update2] = useState("paikpara");
return (
import { useCallback, useMemo, useState } from "react"
import { useEffect } from "react"
import { memo } from "react";
import { BrowserRouter, Route, Routes, useNavigate } from "react-router-dom";
import { Dashboard } from "./components/dashboard";
import { Landing } from "./components/landing";
function App() {
return <BrowserRouter>
import { memo, useCallback, useState } from "react"
import { useEffect } from "react"
import { useMemo } from "react";
function App() {
const [count,setCount]=useState(0);
var handler=useCallback(()=>{
console.log("fuck you");
},[])
return <div>
@itshimashis
itshimashis / .jsx
Last active January 31, 2024 17:51
import { useMemo, useState } from "react"
import { useEffect } from "react"
/*
let's assume we have two crypto wallets where we already have got the amount of returns
but our regular job payment is not yet done, so after getting the regular salary, the crypto additions
should not happend again, here it is addition / but it may be very expensive operation.
useMemo and useCallbacks are usually useful when there are multiple states,
and change in one may trigger some other expensive operation
*/
function App() {
@itshimashis
itshimashis / .jsx
Created January 18, 2024 18:11
Usage of useEffect
import { useState } from "react"
import { useEffect } from "react"
//useState is for component re-render whenever state changes
//useEffect also makes fetch/or whatever thing defined when the items defined in []
//changes
function App() {
const [current,setCurrent]=useState(1);//this is gonna take array of todo(json objects)
return <div>
<button onClick={()=>{