LoginSignup
1
2

More than 5 years have passed since last update.

AsyncStorageをdebugする一番簡単な方法

Last updated at Posted at 2019-04-06

alt
react nativeで、AsyncStorageをデバッグする時、どうやってますか?
私は、まず以下のようなファイルを作成してから、

// AsyncStorageDebug.js
import { AsyncStorage } from 'react-native'

export const AsyncStorageDebug = () =>
  AsyncStorage.getAllKeys((err, keys) =>
    AsyncStorage.multiGet(keys, (error, stores) => {
      window.asdebug = stores
      window.astable = () => console.table(stores)
      window.asclear = () => AsyncStorage.clear()
    })
  )

App.jsで、

// App.js
import { AsyncStorageDebug } from './AsyncStorageDebug'
if (__DEV__) AsyncStorageDebug()

と記述しています。

後は、start remote debug
してから、
f12を押し、chromeのconsoleを開いた後、
asdebug
または、
astable()
と打つと、AsyncStorageの中身を表示出来ます。
asclear()
と打つと、AsyncStorageの中身を全て削除します。

asdebugは、通常のconsole.logの形で表示し、
astable()は、表の形で表示します。

注意

現在chrome のコンソールで、environmentが正しく選択されないバグが発生しているので、
topではなく、debuggerWorker.jsを選択するとasyncStorageがデバッグ出来るようになります。
スクリーンショット 2019-04-08 13.53.14.png

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2