Created
July 3, 2025 11:30
-
-
Save Lahirutech/2ea47de063359de8c03555ed13b523e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState } from 'react' | |
| import './App.css' | |
| export default function App() { | |
| const [url, setUrl] = useState("") | |
| const [shurl, setShUrl] = useState("") | |
| // https://api-ssl.bitly.com/v4/shorten | |
| const postUrl = () => { | |
| fetch("https://api-ssl.bitly.com/v4/shorten", { | |
| method: "post", | |
| headers: { | |
| "Content-Type": "application/json", | |
| "Authorization": 'Bearer ' + import.meta.env.VITE_BITLY | |
| }, body: JSON.stringify({ long_url: url }) | |
| }).then(res => res.json()).then(data => { | |
| console.log(data) | |
| setShUrl(data.link) | |
| }) | |
| } | |
| const handleSubmit = (e: React.MouseEvent<HTMLButtonElement>) => { | |
| e.preventDefault() | |
| console.log("called") | |
| postUrl() | |
| } | |
| return ( | |
| <main> | |
| SHort URL:{shurl} <br /> | |
| Input Url: <input type="te |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment