Expo,React Native AsyncStorage 没有解析 Promise
Expo, React Native AsyncStorage not resolving Promise
React Native 的 AsyncStorage 从未兑现它的承诺。这是代码:
import {Component} from 'react';
import React from 'react';
import {AsyncStorage} from 'react-native';
export default class Session extends Component {
componentDidMount() {
console.log('foo');
debugger; // This hits
AsyncStorage.getItem('token').then(() => {
console.log('baz');
debugger; // This never hits
}).catch(() => {
console.log('catch');
debugger; // This never hits
});
debugger; // This hits
console.log('bar');
}
render() {
return (
<React.Fragment>
{this.props.children}
</React.Fragment>
);
}
}
componentDidMount 方法记录 "foo" 和 "bar" 但不记录 "baz" 或 "catch"
我在 GenyMotion Android 模拟器上 运行。
无论我是否处于远程调试模式,行为都是一样的。
这是我的 package.json 部门:
"dependencies": {
"@expo/samples": "2.1.1",
"eslint-plugin-react-native": "^3.2.1",
"expo": "29.0.0",
"prop-types": "^15.6.2",
"ramda": "^0.25.0",
"react": "16.3.1",
"react-connect-context": "^1.1.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",
"react-native-elements": "^1.0.0-beta5",
"react-navigation": "^2.9.3",
"styled-components": "^3.4.2"
}
这是 React Native 的一个现有问题。几个月前我们遇到了同样的问题。由于我们使用的是 Expo,因此我们决定使用 Expo SecureStore 而不是 AsyncStorage,这完全符合我们的要求。
可以找到有关此问题的更多信息 here。问题标题说只有在远程调试时才会出现,但是看评论不管远程调试与否都会出现
React Native 的 AsyncStorage 从未兑现它的承诺。这是代码:
import {Component} from 'react';
import React from 'react';
import {AsyncStorage} from 'react-native';
export default class Session extends Component {
componentDidMount() {
console.log('foo');
debugger; // This hits
AsyncStorage.getItem('token').then(() => {
console.log('baz');
debugger; // This never hits
}).catch(() => {
console.log('catch');
debugger; // This never hits
});
debugger; // This hits
console.log('bar');
}
render() {
return (
<React.Fragment>
{this.props.children}
</React.Fragment>
);
}
}
componentDidMount 方法记录 "foo" 和 "bar" 但不记录 "baz" 或 "catch"
我在 GenyMotion Android 模拟器上 运行。
无论我是否处于远程调试模式,行为都是一样的。
这是我的 package.json 部门:
"dependencies": {
"@expo/samples": "2.1.1",
"eslint-plugin-react-native": "^3.2.1",
"expo": "29.0.0",
"prop-types": "^15.6.2",
"ramda": "^0.25.0",
"react": "16.3.1",
"react-connect-context": "^1.1.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",
"react-native-elements": "^1.0.0-beta5",
"react-navigation": "^2.9.3",
"styled-components": "^3.4.2"
}
这是 React Native 的一个现有问题。几个月前我们遇到了同样的问题。由于我们使用的是 Expo,因此我们决定使用 Expo SecureStore 而不是 AsyncStorage,这完全符合我们的要求。
可以找到有关此问题的更多信息 here。问题标题说只有在远程调试时才会出现,但是看评论不管远程调试与否都会出现