You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const[name,setName]=useState<string>();const[age,setAge]=useState<number>();const[pageCache,setPageCache,{delete: deletePageCache, storageState }]=usePageCacheState<{props: any;name?: string;age?: number}>('CREATE_PAGE_CACHE_KEY',{subKey: userId,maxCount: 20,expire: 3*24*3600,version: 'f1308000',});/** set to Storage when deps mutation */useEffect(()=>{setPageCache({
props,
name,
age,// others data should be cached...});},[props,name,age]);/** initial state from cache data */useEffect(()=>{if(pageCache){const{ name, age }=pageCache;setName(name);setAge(age);// others cache data sync to state}},[]);return(<formonSubmit={()=>{// submit successdeletePageCache();}}><label>姓名:</label><inputvalue={name}onChange={e=>setName(e.target.value)}></input><label>年龄:</label><inputvalue={age}onChange={e=>setAge(Number(e.target.value))}></input></form>);
The text was updated successfully, but these errors were encountered:
功能介绍
usePageCacheState 用于页面级别的缓存处理方案,通过缓存记录当前页面完整状态,一般会缓存较多数据。
支持的功能:
使用场景
此 hook 常用于提升用户操作体验的场景。比如用户在【创建xx表单页】需要填写表单项较多,经常会主动/不小心退出当前页面,希望同个登录用户再次进入【创建xx表单页】可以恢复刚填写的内容。而其他登录用户进入【创建xx表单页】是重新填写,不读取其他用户的缓存。同时可设置缓存最大数量防止浏览器本地内存溢出问题。可设置缓存过期时间,不回填过于老旧的操作缓存等。
接口设计
使用示例
The text was updated successfully, but these errors were encountered: