Skip to content

Instantly share code, notes, and snippets.

@GalindoSVQ
Created October 31, 2023 05:42
Show Gist options
  • Save GalindoSVQ/7e7f6aa854348564dc18bdc59732092f to your computer and use it in GitHub Desktop.
Save GalindoSVQ/7e7f6aa854348564dc18bdc59732092f to your computer and use it in GitHub Desktop.
import { useState } from 'react';
export default function useDefault<T>(initialState: T, defaultState: T) {
const [value, setValue] = useState<T | null | undefined>(initialState);
if (value === null || typeof value === 'undefined') {
return [defaultState, setValue];
}
}
@GalindoSVQ
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment