feat: Initialize ComFi project with Vite
Setup project structure, dependencies, and basic configuration for the ComFi application. Includes initial setup for Vite, React, TypeScript, Tailwind CSS, and essential development tools. Defines core types and provides a basic README for local development.
This commit is contained in:
18
hooks/useStickyState.ts
Normal file
18
hooks/useStickyState.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
|
||||
export const useStickyState = <T,>(defaultValue: T, key: string): [T, React.Dispatch<React.SetStateAction<T>>] => {
|
||||
const [value, setValue] = useState<T>(() => {
|
||||
try {
|
||||
const stickyValue = window.localStorage.getItem(key);
|
||||
return stickyValue !== null ? JSON.parse(stickyValue) : defaultValue;
|
||||
} catch (e) {
|
||||
return defaultValue;
|
||||
}
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
window.localStorage.setItem(key, JSON.stringify(value));
|
||||
}, [key, value]);
|
||||
|
||||
return [value, setValue];
|
||||
};
|
||||
Reference in New Issue
Block a user