This is a solution to the Shortly URL shortening API Challenge challenge on Frontend Mentor.
Users should be able to:
- View the optimal layout for the site depending on their device's screen size
- Shorten any valid URL
- See a list of their shortened links, even after refreshing the browser
- Copy the shortened link to their clipboard in a single click
- Receive an error message when the
form
is submitted if:- The
input
field is empty - The
input
filed is a url with or withouthttp(s)://www.
- The
Browser.mp4
Mobile.mp4
- Live Site URL: https://shorturl-ivnrice.vercel.app/
- React - JS library
- Styled Components - For styles
- Semantic HTML5 markup
- Flexbox for components
- Mobile-first workflow
- Kanban Methodology
-
Mobile-first workflow.
-
throtle function in Buttons: I had to deal with useState(), so i had to make use of useMemo() in order to preserve the closure across re-renders
-
Solution
const memoThrotleClickURLHandler = useMemo(() => {
const handleShortenUrlClick = async event => {
...
}
return throtle(handleShortenUrlClick, 1500)
}, [])
<form onSubmit={memoThrotleClickURLHandler}>
-
Ellipsis: If the url is too long, it overflows its container.
-
Solution:
p {
...
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
- Stale Closure - This helped me understan what a stale closure is and gave me an idea of how to solve it with an external throtle function
- 3D Art work - Ivanrice_
- Frontend Mentor - @Ivanricee
- Twitter - @ivanrice_