react-native-shared-group-preferences icon indicating copy to clipboard operation
react-native-shared-group-preferences copied to clipboard

couldn't reset the property of an already set value

Open saiganesh-tanneru opened this issue 5 years ago • 8 comments

couldn't reset the property of an already set value, i'm getting the previous value only

saiganesh-tanneru avatar Nov 06 '19 15:11 saiganesh-tanneru

set works fine for the first time but as many times i reset the value i still get the first value

saiganesh-tanneru avatar Nov 06 '19 15:11 saiganesh-tanneru

Can I see the code you use to set the value?

KjellConnelly avatar Nov 06 '19 16:11 KjellConnelly

try {
  await SharedGroupPreferences.setItem("projectsData", projectsData, APPGROUPIDENTIFIER)
  await SharedGroupPreferences.setItem("token", token, APPGROUPIDENTIFIER)
} catch (errorCode) {
  console.log(errorCode)
}

}

saiganesh-tanneru avatar Nov 07 '19 08:11 saiganesh-tanneru

here i jus need to clear the data and pass an empty object and empty string when i logout of the app

saiganesh-tanneru avatar Nov 07 '19 08:11 saiganesh-tanneru

like this in another component:

    deleteData = async () => {
        projectsData = { projectNames: [], allowed_storage: '', team_id: '' }
        try {
            await SharedGroupPreferences.setItem("projectsData", projectsData, APPGROUPIDENTIFIER)
            await SharedGroupPreferences.setItem("token", 'login', APPGROUPIDENTIFIER)
        } catch (errorCode) {
            console.log(errorCode)
        }
    }

saiganesh-tanneru avatar Nov 07 '19 08:11 saiganesh-tanneru

@Abandonedengineer Did you ever find a solution for this?

JoeToeniskoetter avatar Sep 16 '22 15:09 JoeToeniskoetter

True, its only working for first time for me

async function saveDataToSharedStorage(key, data) {
  try {
    const appGroupIdentifier = "Name";
    await SharedGroupPreferences.setItem(key, data, appGroupIdentifier);
    const savedData = await SharedGroupPreferences.getItem(key);
    console.log({valueSaved: savedData});
  } catch (errorCode) {
    // errorCode 0 = There is no suite with that name.
    console.log({errorCode});
  }
};

saveDataToSharedStorage("abc", {});

saveDataToSharedStorage("xyz", {1:1});

I can only get first time set value even if key is different ie. await SharedGroupPreferences.getItem("abc"). ==> {} await SharedGroupPreferences.getItem("xyz"). ==> { error : 1 } ( means it has not been found )

sandeepdhobi avatar Feb 03 '23 07:02 sandeepdhobi

True, its only working for first time for me

async function saveDataToSharedStorage(key, data) {
  try {
    const appGroupIdentifier = "Name";
    await SharedGroupPreferences.setItem(key, data, appGroupIdentifier);
    const savedData = await SharedGroupPreferences.getItem(key);
    console.log({valueSaved: savedData});
  } catch (errorCode) {
    // errorCode 0 = There is no suite with that name.
    console.log({errorCode});
  }
};

saveDataToSharedStorage("abc", {});

saveDataToSharedStorage("xyz", {1:1});

I can only get first time set value even if key is different ie. await SharedGroupPreferences.getItem("abc"). ==> {} await SharedGroupPreferences.getItem("xyz"). ==> { error : 1 } ( means it has not been found )

Sorry this was mistake, forgot to pass appGroupIdentifier to getItem which was causing issue.

    const appGroupIdentifier = 'group.com.company.AppName';
    await SharedGroupPreferences.setItem(key, data, appGroupIdentifier);
    const savedData = await SharedGroupPreferences.getItem(key, appGroupIdentifier);
    

Setting Resetting and only one key on the main app and ShareExtension is working (instant reflection of update ) for me.

sandeepdhobi avatar Mar 15 '23 09:03 sandeepdhobi