Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tiagofrancafernandes/685adf700ea85e830ba969bed6ca86b3 to your computer and use it in GitHub Desktop.
Save tiagofrancafernandes/685adf700ea85e830ba969bed6ca86b3 to your computer and use it in GitHub Desktop.
dev-nuxt Snippets
const toBool = (val) => {
    return [
        false, 'false', '', null, 'null', undefined, 'undefined',
        '0', 0, 'no', 'n', 'off', 'nao', 'não', 'no', 'n', 'off',
    ].includes(val);
}

const expandDebugContent_FromLs = () => {
    if (typeof localStorage !== 'undefined') {
        return toBool(localStorage?.getItem('expandDebugContent'), false);
    }

    return null;
};

// -------------- most important
const expandDebugContent = useState('expandDebugContent', expandDebugContent_FromLs);

if (expandDebugContent.value === null) {
    expandDebugContent.value = expandDebugContent_FromLs();
}

watch(
    () => expandDebugContent.value,
    () => {
        if (typeof localStorage !== 'undefined') {
            localStorage.setItem('expandDebugContent', expandDebugContent.value);
        }
    }
)
// -------------- most important end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment