-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react2-week1/Viki #299
base: main
Are you sure you want to change the base?
react2-week1/Viki #299
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This project is 🔥 Well done Viki 👏
I've left just some suggestions, but all good besides that
|
||
function App() { | ||
return ( | ||
<> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to use Fragment, please remove it :)
|
||
return ( | ||
<div> | ||
<input |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! This is just a "pro tip" :D if you wrap the input by form element it also allows you to use keys such as "enter" to search
example:
const handleSearch = (e) => {
e.preventDefault();
fetchUsers();
};
return (
<form onSubmit={handleSearch}>
setIsLoading(true); | ||
setError(null); | ||
|
||
fetch(`https://api.github.com/search/users?q=${query}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the query is empty it will throw: Error fetching: Failed to fetch users
, please handle this scenario
<> | ||
<div className="app-container"> | ||
<h1>Github user searcher</h1> | ||
<GithubSearchProvider> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively (its more common) you can wrap the whole app by the provider, but this is also fine :)
import { GithubSearchContext } from "../context/GithubSearchContext"; | ||
|
||
const SearchInput = () => { | ||
const { query, setQuery, fetchUsers } = useContext(GithubSearchContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the more common way how to access the context could be
// GithubSearchContext.jsx
export const useGithub = () => {
return useContext(GithubSearchContext);
};
// Search Input.jsx
const { query, setQuery, fetchUsers } = useGithub()
But your way is also correct. Well done
Github user searcher