react-native-shared-group-preferences
react-native-shared-group-preferences copied to clipboard
couldn't reset the property of an already set value
couldn't reset the property of an already set value, i'm getting the previous value only
set works fine for the first time but as many times i reset the value i still get the first value
Can I see the code you use to set the value?
try {
await SharedGroupPreferences.setItem("projectsData", projectsData, APPGROUPIDENTIFIER)
await SharedGroupPreferences.setItem("token", token, APPGROUPIDENTIFIER)
} catch (errorCode) {
console.log(errorCode)
}
}
here i jus need to clear the data and pass an empty object and empty string when i logout of the app
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)
}
}
@Abandonedengineer Did you ever find a solution for this?
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 )
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.