This is a solution to the Shortly URL shortening API Challenge challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
This is a landing page for a company called Shortly that provides a URL shortening API. The page is fully responsive and built with React. The page is styled with Tailwind. The page is deployed on Netlify.
Users should be able to:
form
is submitted if:input
field is empty
Note: These are just examples. Delete this note and replace the list above with your own choices
I learned how to use React-Query to fetch data from an API.
import { useQuery } from '@tanstack/react-query';
function useShortenLink(longLink) {
return useQuery(
['linkData', longLink],
() => fetch('/.netlify/functions/shortenLink', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ url: longLink }),
}).then((res) => res.json()),
{
enabled: !!longLink, // only run the query if longLink is defined
staleTime: Infinity, // prevent automatic refetching when the data is stale
cacheTime: Infinity, // keep the data in the cache indefinitely
}
);
}
export default useShortenLink;
I want to improve the styling of the page and refine it a bit further, but since I am on some time constraints due to other obligations, I wasn't able to do so at this point.