在发送POST请求后,ReactNative重定向按钮

时间:2020-08-29 17:36:35

标签: react-native

我只是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>
}

0 个答案:

没有答案