Skip to content

Docs: Async Storage website #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/workflows/ci.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/website-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Website Deployment
on:
push:
branches:
- master
paths:
- 'website/**'

jobs:
deploy:
name: Deploy website
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Cache/restore dependencies
uses: actions/cache@v1
id: cache
with:
path: ./website/node_modules
key: website-${{ hashFiles('website/yarn.lock') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile --cwd ./website
- name: Add ssh keys
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
echo "${{ secrets.GH_PAGES_DEPLOY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
cat <<EOT >> ~/.ssh/config
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa
EOT
- name: Release
working-directory: ./website
env:
USE_SSH: true
GIT_USER: git
run: |
git config --global user.email "[email protected]"
git config --global user.name "gh-actions"
yarn deploy



1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ docs
.idea
bin/test.js
codorials
website/
125 changes: 4 additions & 121 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,131 +14,14 @@ An asynchronous, unencrypted, persistent, key-value storage system for React Nat

## Getting Started

Head over to [documentation](https://react-native-community.github.io/async-storage/) to learn more.

### Install

```
$ yarn add @react-native-community/async-storage
```

### Link

- **React Native 0.60+**

[CLI autolink feature](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md) links the module while building the app.

Use CocoaPods to add the native `RNAsyncStorage` to your project:

```bash
$ npx pod-install
```

- **React Native <= 0.59**


```bash
$ react-native link @react-native-community/async-storage
```

*Note:* For `macOS` and `Windows` the [manual linking](docs/Linking.md) is currently the only linking option.


See docs for [manual linking guide.](docs/Linking.md)

### **Upgrading to React Native *0.60+***

React Native 0.60+ comes with `autolinking` feature, which automatically links Native Modules in your project.
In order to get it to work, make sure you `unlink` `Async Storage` first (if you had linked it before):

```bash
$ react-native unlink @react-native-community/async-storage
```


## Usage

AsyncStorage can only store `string` data, so in order to store object data you need to serialize it first.
For data that can be serialized to JSON you can use `JSON.stringify()` when saving the data and `JSON.parse()` when loading the data.


### Importing

```js
import AsyncStorage from '@react-native-community/async-storage';
```

### Storing data

`setItem()` is used both to add new data item (when no data for given key exists), and to modify exiting item (when previous data for given key exists).

#### Storing string value
```jsx
const storeData = async (value) => {
try {
await AsyncStorage.setItem('@storage_Key', value)
} catch (e) {
// saving error
}
}
```

#### Storing object value
```jsx
const storeData = async (value) => {
try {
const jsonValue = JSON.stringify(value)
await AsyncStorage.setItem('@storage_Key', jsonValue)
} catch (e) {
// saving error
}
}
```

### Reading data

`getItem` returns a promise that either resolves to stored value when data is found for given key, or returns `null` otherwise.

#### Reading string value
```jsx

getData = async () => {
try {
const value = await AsyncStorage.getItem('@storage_Key')
if(value !== null) {
// value previously stored
}
} catch(e) {
// error reading value
}
}

```
#### Reading object value

```jsx

getData = async () => {
try {
const jsonValue = await AsyncStorage.getItem('@storage_Key')
return jsonValue != null ? JSON.parse(jsonValue) : null;
} catch(e) {
// error reading value
}
}

```

## Advanced usage
See docs for [API and more examples](docs/API.md) or [advanced usages](docs/advanced).

## Writing tests

Using [Jest](https://jestjs.io/) for testing? Make sure to check out [docs on how to integrate it with this module.](./docs/Jest-integration.md)

## Contribution
Pull requests are welcome. Please open an issue first to discuss what you would like to change.

See the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out.
See the [CONTRIBUTING](CONTRIBUTING.md) file for more information.

## License

MIT
MIT.
22 changes: 0 additions & 22 deletions docs/advanced/DedicatedExecutor.md

This file was deleted.

20 changes: 20 additions & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
20 changes: 20 additions & 0 deletions website/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Async Storage website

Built using [Docusaurus 2](https://v2.docusaurus.io/).


## Development

### Installation

```
$ yarn
```

### Run locally

```
$ yarn start
```

This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server.
46 changes: 5 additions & 41 deletions docs/API.md → website/docs/API.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
# Async Storage API with examples.
---
id: api
title: API
sidebar_label: API
---



**Table of Contents**
- [getItem](#getItem)
- [setItem](#setItem)
- [mergeItem](#mergeItem)
- [removeItem](#removeItem)
- [getAllKeys](#getAllKeys)
- [multiGet](#multiGet)
- [multiSet](#multiSet)
- [multiMerge](#multiMerge)
- [multiRemove](#multiRemove)
- [clear](#clear)
- [flushGetRequests](#flushGetRequests)
- [useAsyncStorage](#useAsyncStorage)

<br />

<!-- ------------------------ GET ITEM ------------------------ -->

## `getItem`
Expand Down Expand Up @@ -516,29 +503,6 @@ clearAll = async () => {

```


<br />
<br />


<!-- ------------------------ FLUSH GET REQUEST ------------------------ -->


## `flushGetRequests`

Flushes any pending requests using a single batch call to get the data.

**Signature**:

```js
static flushGetRequests(): void
```

**Returns**:

`undefined`


<!-- ------------------------ HOOKS ------------------------ -->


Expand Down
34 changes: 34 additions & 0 deletions website/docs/Installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
id: install
title: Installation
sidebar_label: Installation
---



### Get library

```bash
yarn add @react-native-community/async-storage
```

### Link

- **React Native 0.60+**

[CLI autolink feature](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md) links the module while building the app.

Use CocoaPods to add the native `RNAsyncStorage` to your project:

```bash
npx pod-install
```

- **React Native <= 0.59**


```bash
react-native link @react-native-community/async-storage
```

*Note:* For `Windows` the [manual linking](link) is currently the only linking option.
Loading