-
-
Notifications
You must be signed in to change notification settings - Fork 120
Description
I am using indexes and storing the key in an array and the data in a Map.
But when I add a new item, it does not reflect on the UI. I have to refresh the app to reflect the new item on the UI. Update or delete is working fine. The only issue is with the new item.
Below is the sample:
// Transaction to push key in index
MMKV.transactions.register('object', 'beforewrite', (key: string) => {
if (key.startsWith('form') && key !== 'form') {
let indexForForm = MMKV.getArray('form') || [];
MMKV.setArray(indexForTag.push(key));
}
});
// To Create Form
MMKV.setMap(form_${Date.now()},{name:"",age:24});
//For UI
const formIndex = useMMKVStorage("form",MMKV,[]);
const [forms] = useIndex(formIndex,"object" MMKV);
console.log(formIndex,"formIndex"); <---- This will show new index;
console.log(forms,"formIndex"); <---- This won't show new item.
return <View>
<FlatList
data={forms}
renderItem={...}
>
Expected behavior
UI should reflect asap a new item added.
Platform Information:
- OS: IOS, Android
- React Native Version : 0.79.2
- Library Version: 0.11