react-native-simple-local-storage
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

react-native-simple-local-storage

@react-native-community/async-storage 组件的同步写法

原理

一开始就将保存的数据全部导入内存中,初始化完毕后就可以直接在内存操作,速度更快

Install

$ yarn add react-native-simple-local-storage

Simple use

 //在入口文件中;
 import 'react-native-simple-local-storage';
 function App(){
   const [isReady, setReady] = useState(false);
   useEffect(() => {
     global.localStorage.isReady.then(() => setReady(true));
    }, []);
   if (!isReady) {
     return null;
   }
   return (<View>
            <Button onPress={() => global.localStorage.setItem('key', 'value')}>setItem</Button>
            <Button onPress={() => console.log(localStorage.getItem('key'))}>getItem</Button>
            <Button onPress={() => localStorage.removeItem('key')}>removeItem</Button>
            <Button onPress={() => localStorage.clear()}>clear</Button>
            <Button onPress={() => console.log(global.localStorage.length)}>length</Button>
            <Button onPress={() => console.log(global.localStorage.byteSize)}>byteSize</Button>
   </Layout>);
 }

Package Sidebar

Install

npm i react-native-simple-local-storage

Weekly Downloads

4

Version

0.1.1

License

ISC

Unpacked Size

5.36 kB

Total Files

4

Last publish

Collaborators

  • xiegq