0
0
React Nativemobile~20 mins

MMKV for fast storage in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MMKV Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2:00remaining
What happens when you store and retrieve a value using MMKV?
Consider this React Native code using MMKV storage. What will be the output shown on the screen after pressing the button?
React Native
import React, { useState } from 'react';
import { View, Text, Button } from 'react-native';
import { MMKV } from 'react-native-mmkv';

const storage = new MMKV();

export default function App() {
  const [value, setValue] = useState('');

  const saveAndLoad = () => {
    storage.set('greeting', 'Hello MMKV');
    const stored = storage.getString('greeting');
    setValue(stored ?? '');
  };

  return (
    <View>
      <Button title="Save & Load" onPress={saveAndLoad} />
      <Text>{value}</Text>
    </View>
  );
}
AThe text remains empty because MMKV does not save strings.
BThe text 'Hello MMKV' appears below the button after pressing it.
CAn error occurs because MMKV requires async/await for set and get.
DThe app crashes because MMKV is not initialized properly.
Attempts:
2 left
💡 Hint
MMKV stores data synchronously and getString returns the saved string immediately.
lifecycle
intermediate
1:30remaining
When is MMKV storage data persisted in React Native?
In a React Native app using MMKV, when is the data saved by MMKV guaranteed to be persisted?
AImmediately after calling storage.set, data is saved to disk synchronously.
BData is saved only when you call a special save method explicitly.
COnly when the app goes to background, MMKV flushes data to disk asynchronously.
DData is saved only when the app is closed by the user.
Attempts:
2 left
💡 Hint
Think about synchronous vs asynchronous storage methods.
🔧 Debug
advanced
2:00remaining
Why does this MMKV getString call return null unexpectedly?
Look at this code snippet: const storage = new MMKV(); storage.set('key', 'value'); const val = storage.getString('Key'); Why does val return null?
ABecause MMKV keys are case-sensitive and 'Key' is different from 'key'.
BBecause getString requires an async call and this is synchronous.
CBecause MMKV does not support string values, only numbers.
DBecause the storage instance was not initialized with a namespace.
Attempts:
2 left
💡 Hint
Check the spelling and casing of keys carefully.
🧠 Conceptual
advanced
1:30remaining
What is a key advantage of MMKV over AsyncStorage in React Native?
Choose the main advantage MMKV provides compared to AsyncStorage for React Native apps.
AMMKV automatically encrypts all data without configuration.
BMMKV requires no native setup unlike AsyncStorage.
CMMKV offers faster synchronous read/write operations with less CPU usage.
DMMKV supports only JSON objects while AsyncStorage supports strings.
Attempts:
2 left
💡 Hint
Think about performance and how data is accessed.
📝 Syntax
expert
2:30remaining
Which MMKV usage snippet correctly stores and retrieves a boolean value?
Select the code snippet that correctly saves a boolean and retrieves it using MMKV in React Native.
A
storage.set('flag', 'true');
const val = storage.getBoolean('flag');
B
storage.setBoolean('flag', true);
const val = storage.get('flag');
C
storage.setBool('flag', true);
const val = storage.getBool('flag');
D
storage.set('flag', true);
const val = storage.getBoolean('flag');
Attempts:
2 left
💡 Hint
Check the MMKV API method names carefully.