Skip to content

Commit a083f3a

Browse files
committed
fix: 修复 getItem 返回 string 类型时值不正确的问题
1 parent 1b18115 commit a083f3a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

__tests__/AsyncStorage.mock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ jest.mock("@react-native-community/async-storage", () => {
22
let _value = {
33
"@storageold_number": JSON.stringify({type: "number", value: JSON.stringify(1)}),
44
"userold_number": JSON.stringify({type: "number", value: JSON.stringify(1)}),
5-
"@storageold_string": JSON.stringify({type: "string", value: "hello"}),
5+
"@storageold_string": JSON.stringify({type: "string", value: JSON.stringify("hello")}),
66
"@storageold_date": JSON.stringify({type: "date", value: JSON.stringify(new Date("2010-01-01 00:00:00"))}),
77
};
88
return {

components/EnhancedAsyncStorage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default class EnhancedAsyncStorage implements IStorage {
1818
case "number":
1919
return parseFloat(item.value);// new Number(item.value);
2020
case "string":
21-
return item.value;
21+
console.log(`string value : ${item.value}`);
22+
return JSON.parse(item.value);
2223
default:
2324
return JSON.parse(item.value);
2425
}

0 commit comments

Comments
 (0)