diff --git a/src/plays/url-shortner/UrlShortner.jsx b/src/plays/url-shortner/UrlShortner.jsx index 395c99a733..93e4b9583f 100644 --- a/src/plays/url-shortner/UrlShortner.jsx +++ b/src/plays/url-shortner/UrlShortner.jsx @@ -10,6 +10,15 @@ function UrlShortner(props) { const [error, setError] = useState(null); const handleSubmit = async () => { try { + if (!userInput.trim()) { + toast('Please enter a valid URL.', { + position: 'top-center', + type: 'error', + autoClose: 1500 + }); + + return; + } setShortenedLink(''); const response = await axios.get(`https://tinyurl.com/api-create.php?url=${userInput}`); if (response.data) { @@ -62,9 +71,10 @@ function UrlShortner(props) {

React URL Shortener

-
+
-
- {error &&
{error}
} -
- {shortenedLink ? shortenedLink : 'Shorten An URL First'} + {error &&
{error}
} + {shortenedLink && ( +
+

Here's your shortened URL:

+ +
+
+ {shortenedLink} +
+ +
- -
+ )}