Skip to content

useIndex for new item is not reactive #378

@sumansaurabh00001

Description

@sumansaurabh00001

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions