v0.5.5
Introducing useMMKVStorage
Hook 🎉
Thanks to the power of JSI, we now have our very own useMMKVStorage Hook. Think of it like a persisted state that will always write every change in storage and update your app UI instantly. It doesn't matter if you reload the app or restart it. Here's a small demo:
Import MMKVStorage
and useMMKVStorage
Hook.
import MMKVStorage, { useMMKVStorage } from "react-native-mmkv-storage";
Initialize the MMKVStorage
instance.
const MMKV = new MMKVStorage.Loader().initialize();
Next, in our component we are going to register our hook.
const App = () => {
const [user, setUser] = useMMKVStorage("user", MMKV);
return (
<View>
<Text>{user}</Text>
</View>
);
};
To update value of "user"
in storage and your App
component will automatically rerender.
setUser("andrew");
// or you can do this too anywhere in the app:
MMKV.setString("user", "andrew");
Head over to the docs for complete usage.