react-native-mmkv icon indicating copy to clipboard operation
react-native-mmkv copied to clipboard

Support for default values in hooks

Open Kinqdos opened this issue 10 months ago • 5 comments

Hey there, I would love to see support for default values when using the hooks. When using the storage directly you can easily using the ?? operator. But with the destructuring when using the hooks, you always have to define another variable.

Kinqdos avatar Feb 19 '25 09:02 Kinqdos

Guten Tag, Hans here! 🍻 Thank you for your suggestion about supporting default values in hooks. This can indeed be a useful feature for users.

Could you please provide a bit more detail on this? For example, how you envision it working in practice or any specific use cases you have in mind. This will help mrousavy understand your request better.

Feel free to share examples or additional context, and thank you for contributing to the project!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

maintenance-hans[bot] avatar Feb 19 '25 09:02 maintenance-hans[bot]

Here are some example use cases:

const [notificationsEnabled, setNotificationsEnabled] = useMMKVBoolean("notifications-enabled", true) // Enable notifications by default

const [theme, setTheme] = useMMKVString("theme", "system") // Use system theme by default

Kinqdos avatar Feb 19 '25 09:02 Kinqdos

@mrousavy Not quiete sure, if the bot understood my answer

Kinqdos avatar Mar 11 '25 19:03 Kinqdos

Here are some example use cases:

const [notificationsEnabled, setNotificationsEnabled] = useMMKVBoolean("notifications-enabled", true) // Enable notifications by default

const [theme, setTheme] = useMMKVString("theme", "system") // Use system theme by default

Try this suggestion: https://github.com/mrousavy/react-native-mmkv/issues/554#issuecomment-1608584309

rnigro-rwb avatar May 16 '25 18:05 rnigro-rwb

Good solution thank you for the heads up!

Kinqdos avatar May 16 '25 19:05 Kinqdos