UNPKG

@oberoncms/core

Version:

OberonCMS is a cloud deployable CMS written in typescript based on the Puck visual editor

21 lines (20 loc) 685 B
import { useState, useEffect, useCallback } from "react"; const encode = (path, componentKey) => `puck-demo:${window.btoa(componentKey)}:${path}`; const useLocalData = (path, config) => { const componentKey = Object.keys(config.components).join("-"); const [data, setData] = useState(); useEffect(() => { const dataStr = localStorage.getItem(encode(path, componentKey)); if (dataStr) { setData(JSON.parse(dataStr)); } }, [path, componentKey]); const setLocalData = useCallback( (data2) => localStorage.setItem(encode(path, componentKey), JSON.stringify(data2)), [path, componentKey] ); return [data, setLocalData]; }; export { useLocalData };