Skip to content
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

@dev-plugins/react-native-mmkv - not showing the boolean data from the mmkv store #44

Open
sainjay opened this issue Jul 9, 2024 · 5 comments

Comments

@sainjay
Copy link

sainjay commented Jul 9, 2024

Boolean data is not showing the Browser for mmkv dev plugin. Can anyone else confirm if they're facing this too?

image
@g-otn
Copy link

g-otn commented Nov 13, 2024

I'm facing the same problem. Using:

  • react-native-mmkv: 2.12.2
  • @dev-plugins/react-native-mmkv: 0.0.1
  • expo: 51.0.38
  • react-native: 0.74.5

@g-otn
Copy link

g-otn commented Nov 13, 2024

I believe it has to do with the dev-plugin using getString always:

return keys?.map(key => [key, storage.getString(key)]);

I don't think react-native-mmkv provides a way to retrieve the type of the value you stored (string, boolean, number or ArrayBuffer), so I think a solution would be to use all getters (getBoolean, etc), and show the value of the one which didn't return undefined.

Reading their Contributing though, not sure if this will get attention anytime soon

@sainjay
Copy link
Author

sainjay commented Nov 13, 2024

@g-otn I tried doing that in local node_module but couldn't figure out how to build.

@Kudo can we add getters for-
boolean: storage.getBoolean(key)
number: storage.getNumber(key)

@g-otn
Copy link

g-otn commented Nov 13, 2024

I've created a patch using patch-package as a workaround.

It seems to properly display string, numbers and booleans. However displaying Uint8Array values and editing values other than strings don't work properly.

patches/@dev-plugins+react-native-mmkv+0.0.1.patch
diff --git a/node_modules/@dev-plugins/react-native-mmkv/build/useMMKVDevTools.js b/node_modules/@dev-plugins/react-native-mmkv/build/useMMKVDevTools.js
index bb8b9e0..a556072 100644
--- a/node_modules/@dev-plugins/react-native-mmkv/build/useMMKVDevTools.js
+++ b/node_modules/@dev-plugins/react-native-mmkv/build/useMMKVDevTools.js
@@ -41,7 +41,18 @@ export function useMMKVDevTools({ errorHandler, storage = new MMKV() } = {}) {
         try {
             subscriptions.push(on('getAll', async () => {
                 const keys = storage.getAllKeys();
-                return keys?.map(key => [key, storage.getString(key)]);
+                /**
+                 * PATCH
+                 * 
+                 * Workaround to display number and boolean values.
+                 * May break edit interface, doesn't display Uint8Array values.
+                 * See https://github.com/expo/dev-plugins/issues/44
+                 */
+                return keys?.map(key => [key, 
+                    storage.getString(key) || 
+                    storage.getNumber(key)?.toString() || 
+                    storage.getBoolean(key)?.toString()
+                ]);
             }));
         }
         catch (e) {

@sainjay
Copy link
Author

sainjay commented Nov 14, 2024

Thanks for sharing @g-otn. Works as expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants