Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

react2-week1/Viki #299

wants to merge 1 commit into from

Conversation

VictoriaDem17
Copy link

Github user searcher

@github-actions github-actions bot changed the title react2-week1 react2-week1/Viki Apr 16, 2024
Copy link

@BrantalikP BrantalikP left a 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 (
<>

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

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}`)

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>

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);

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants