Skip to content

Instantly share code, notes, and snippets.

@bantawa04
bantawa04 / helper.ts
Created December 2, 2024 11:31
Custom react hook for persisted state without use state
import { useState } from 'react';
export default function usePersistedState<T>(
key: string,
initialValue: T
): [T, React.Dispatch<React.SetStateAction<T>>] {
// Initialize state with a function to avoid unnecessary localStorage calls
const [value, setValueState] = useState<T>(() => {
try {
const item = localStorage.getItem(key);
@bantawa04
bantawa04 / ImageKitUtility.php
Last active June 16, 2022 09:50
Image Kit in Laravel
<?php
namespace App\Traits;
use Intervention\Image\Facades\Image;
use ImageKit\ImageKit;
trait ImageKitUtility
{
//Upload to imagekit