An open API service indexing awesome lists of open source software.

https://github.com/puti94/react-native-simple-local-storage


https://github.com/puti94/react-native-simple-local-storage

Last synced: over 1 year ago
JSON representation

Awesome Lists containing this project

README

          

# react-native-simple-local-storage

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

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

### Install

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

### Simple use
```jsx
//在入口文件中;
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 (
global.localStorage.setItem('key', 'value')}>setItem
console.log(localStorage.getItem('key'))}>getItem
localStorage.removeItem('key')}>removeItem
localStorage.clear()}>clear
console.log(global.localStorage.length)}>length
console.log(global.localStorage.byteSize)}>byteSize
);
}
```