GitHub User Search app using React and Tailwindcss
Design comparison
Solution retrospective
Hello, coding community 👋
I had a lot of fun with this challenge 🤥😅. It was supposed to be a small challenge for start, but in the end it turned out to be great eye-opener 😳. This little side project reminded me to look into Fetch API, Promises and Typescript.
I'm not quite sure of my custom search hook and the way I use it, I'd love to hear some best practices or more ideas of how to improve it.
Also I'd be happy to know your opinion about:
- tailwind class-based styling: are you more for inline styling or writing it in separate file?
- rendering elements based on props (based on href to be more specific) (ex. UserLink component in my solution) - is there a better solution, or do you use it the same way?
If you'll find any other ways to improve my code, please be sure to reach out here or in the slack channel.
Community feedback
- @nicodes-devPosted about 2 years ago
Hi Daniel! You've done a great job on this challenge. Only thing I think that is missing is the opacity when the link is unavailable, overall it looks great.
// In your App.tsx const [searchData, setSearchData] = useState<DefaultData>(defaultData) useEffect(() => { setSearchData(defaultData) }, [])
You already set the default value of searchData to defaultData so I don't think the useEffect is still needed. But you can improve this by passing your fetch function to search for the default user inside useEffect.
// In App.tsx useEffect(() => { const asyncFn = async = () => { await handleSubmit('octocat') } asyncFn() },[handleSubmit]
But if you pass your handleSubmit function inside useEffect, you need to memoize it by wrapping it in a useCallback hook because it will cause an infinite loop inside the useEffect.
// In useSearchSubmit hook const handleSubmit = useCallback (async() => { // all your codes } ,[])
I haven't learn typescript yet but I hope this is still helpful.
1@DanoBrozPosted about 2 years ago@baldmannnnn Thanks for reaching out and giving the time to review my code 😊.
- There already was opacity class based on empty link, I've made sure to make it more clear
- Sometimes looking too much into code makes you forget redundant setters, thanks for the point.
- I'm not really sure what you ment by using the async function with useCallback. If you'll have some time for spare, please send me DM on Slack.
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord