ammarahm-ed / react-native-mmkv-storage

An ultra fast (0.0002s read/write), small & encrypted mobile key-value storage framework for React Native written in C++ using JSI
https://rnmmkv.now.sh
MIT License
1.59k stars 111 forks source link

Trying to set a array value to hook for type object is not allowed. #301

Closed abdullahIsa closed 1 year ago

abdullahIsa commented 1 year ago

Describe the bug Hello i am getting "Trying to set a array value to hook for type object is not allowed." .

Mostly when app is doing authentication I would pass the data this way by a function data is an array,

const set_users_bookMarks_local_db = runAfterInteractionsWrapper(
  ({key = undefined, data = []}) => {
    return new Promise((resolve, reject) => {
      try {
        if (key === undefined || key === null)
          return resolve({
            error: true,
            message: 'To proceed, users key is required!',
          });
        storage.setMap(`bookMarks.${key}`, data);
        resolve({
          error: false,
          data
        });
      } catch (error) {
        resolve({
          error: true,
          message: 'Failed to update bookMarks in local db!',
        });
      }
    });
  },
);

When I am in the page where I am using useMMKVStorage,I would get or update data this way

const [data, setData] = useMMKVStorage(
    `bookMarks.${globalStore.user.usersKey}`,
    storage,
    [],
);

Whenever I tried passing array to setData I get the error, what am I missing ?

abdullahIsa commented 1 year ago

Update to this, i just realized i was supposed to use setArray not setMap