Skip to content

Instantly share code, notes, and snippets.

View alperkilickaya's full-sized avatar
🧑‍💻
Solving problems

Alper Kilickaya alperkilickaya

🧑‍💻
Solving problems
View GitHub Profile
@alperkilickaya
alperkilickaya / useLocalStorageSize.js
Last active January 8, 2024 10:55
custom react hook for calculating local storage size in kb.
import { useState, useEffect } from "react";
export function useLocalStorageSize() {
const [localStorageSize, setLocalStorageSize] = useState(0);
useEffect(() => {
const calculateLocalStorageSize = () => {
let totalSize = 0;
for (let key in localStorage) {
if (Object.prototype.hasOwnProperty.call(localStorage, key)) {
@alperkilickaya
alperkilickaya / useHttp.js
Last active May 31, 2023 15:11
React Custom Http Hook with AbortController
import { useState, useCallback, useRef, useEffect } from "react";
export const useHttpClient = () => {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState();
// bu hook'un kullanıldığı component her render olduğunda aynı kalacak bir değişken oluşturur.
const activeHpptRequests = useRef([]);
const sendRequest = useCallback(
@alperkilickaya
alperkilickaya / search.js
Last active January 2, 2023 21:52
Make http request in React useEffect hook after 0.5 seconds later stopping keystroke by using setTimeout function and useRef hook.
import React, { useState, useEffect, useRef } from 'react';
import Card from '../UI/Card';
import './Search.css';
const Search = React.memo(props => {
const { onLoadIngredients } = props;
const [enteredFilter, setEnteredFilter] = useState('');
const inputRef = useRef();