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
- Host: GitHub
- URL: https://github.com/puti94/react-native-simple-local-storage
- Owner: puti94
- Created: 2020-04-10T10:10:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-10T10:11:36.000Z (over 6 years ago)
- Last Synced: 2024-10-11T00:04:23.046Z (almost 2 years ago)
- Language: TypeScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
);
}
```