const handleSubmit = async () => {
const uri = encodeURIComponent(inputValue.toString());
const url = "https://cleanuri.com";
const shortenAPI = `${url}/api/v1/shorten`;
if(uri!==""){
try {
const res = await fetch(shortenAPI, {
method: "POST",
body: `url=${uri}`,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
});
if (!res.ok) {
throw new Error(`HTTP error! status: ${res.status}`);
}
const dataJSON = await res.json();
setData([...data, { input: inputValue, result: dataJSON.result_url }]);
setInputValue("");
} catch (error) {
console.error("Fetch error:", error);
}
}
else{
setAlertInput(!alertInput)
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter