下载依赖
npm install localforage
接下来像使用 localstore一样使用它
import React, { useEffect } from 'react';
import localForage from 'localforage';const App = () => {useEffect(() => {// 保存数据async function storeData() {try {await localForage.setItem('user', { id: 1, name: 'John Doe' });// 读取数据const userData = await localForage.getItem('user');console.log(userData);} catch (err) {// 错误处理console.error(err);}}storeData();}, []);return (<div><h1>Welcome to IndexedDB with localForage</h1></div>);
};export default App;