如何解决fetch 和 axios 在 PlaidLink 组件中不起作用,我该如何解决这个问题?
我正在尝试从 <PlaidLink />
组件 onSuccess 道具中向我的后端发出一个简单的 POST 请求。但是,使用 fetch 时,我收到一个奇怪的警告:
Require cycle: node_modules/react-native-plaid-link-sdk/node_modules/react-native/Libraries/Network/fetch.js -> node_modules/react-native-plaid-link-sdk/node_modules/react-native/Libraries/Network/fetch.js
而且我也收到一条错误消息:
TypeError: undefined is not a function (near '...fetch...')
这怎么可能? fetch 显然是一个函数,因为它是 react native API 的一部分。当我尝试在 onSuccess 道具中使用 fetch 时,我只会收到此错误。 fetch 在我的应用中的其他地方也能正常工作。
我也尝试过使用 axios,因为我认为库中可能会发生一些奇怪的导入/名称冲突。但是 axios 甚至不会发出 HTTP 请求。它什么都不做。同样,axios 在我的代码库的其他地方工作得很好,只有在 onSuccess 内部我才遇到问题。我该如何解决?下面是我的组件和代码。
const PlaidComponent = (props) => {
return (
<PlaidLink
tokenConfig={{
token: props.token,}}
onSuccess={(success) => {
fetch(API_URL + '/plaidPermanentToken',{
method: 'POST',headers: {
Accept: 'application/json','Content-Type': 'application/json',},body: JSON.stringify({
value: success.publicToken,}),})
.then((response) => {
console.log('Token exchange complete');
console.log(response);
})
}}>
<View style={styles.button}>
<Text style={styles.textStyle}>Add Account</Text>
</View>
</PlaidLink>
);
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。