我只是ReactNative
的新手,并且在发送POST
请求后如何实现对链接的重定向方面遇到问题。下面是我的代码。提交按钮请求后,我想重定向。 checkoutUrl将是我生成的在请求后重定向的链接。
const [sourceId, setSourceId] = useState('');
const [checkoutUrl, setCheckoutUrl] = useState('');
const handlePayment = async () => {
const body = { currency: 'PHP', type: 'test', user_id: data.userId, amount }
gcashPaymentSourceApi(
body,
res => {
setSourceId(res.data.result.data.id);
setCheckoutUrl(res.data.checkout_url);
},
err => {
console.log(err.response.data);
}
)
}
const OpenUrl = ({ url }) => {
const handleUrlPress = useCallback(async () => {
const supported = await Linking.canOpenURL(url);
if (supported) {
await Linking.openURL(url);
} else {
Alert.alert(`Don't know how to open this URL: ${url}`);
}
}, [url]);
return <TouchableOpacity onPress={handlePayment}>
<Text>Submit</Text>
</TouchableOpacity>
}