Skip to content
Open
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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ const [age, setAge] = useMMKVNumber('user.age')
const [isMmkvFastAsf, setIsMmkvFastAf] = useMMKVBoolean('is-mmkv-fast-asf')
```

To avoid the possibility of the variable being `undefined` it can be given a default value which will be used in the case that a value is not found for the given `key`.

```js
// default to 'Marc' if 'user.name' key is not found
const [username = 'Marc', setUsername] = useMMKVString('user.name')

// default to 21 if 'user.age' is not found
const [age = 21, setAge] = useMMKVNumber('user.age')

// default to true if 'is-mmkv-fast-asf' is not found
const [isMmkvFastAsf = true, setIsMmkvFastAf] = useMMKVBoolean('is-mmkv-fast-asf')
```

### Keys

```js
Expand Down