GitHub User Search app using React and Tailwindcss

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.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @nicodes-dev
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.
Join 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