Skip to content

Commit

Permalink
fix pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignaherrero committed Apr 9, 2022
1 parent a6e26ef commit 7e3037e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions components/pagination/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const statusFetch = {
notfound: "notfound",
};

export default function Pagination({ articles, getValues, setArticles }) {
const [page, setPage] = useState(1);
export default function Pagination({ articles, getValues, setArticles, page, setPage }) {

useEffect(() => {
const getOtherPage = async () => {
Expand Down
4 changes: 2 additions & 2 deletions components/search/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const statusFetch = {
notfound: "notfound",
};

export default function Search({ setArticles, articles, handleSubmit, register }) {
export default function Search({ setArticles, articles, handleSubmit, register, setPage }) {
const onSubmit = async (dataForm) => {
setArticles({ data: [], found: statusFetch.pending });
try {
Expand All @@ -25,7 +25,7 @@ export default function Search({ setArticles, articles, handleSubmit, register }
data = await response.json();
setArticles({ ...data, found: statusFetch.notFound });
}
// setPage(1);
setPage(1);
} catch (err) {
console.log(err);
}
Expand Down
6 changes: 4 additions & 2 deletions pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function Home() {
data: [],
found: statusFetch.idle,
});

const [page, setPage] = useState(1);
const {
register,
handleSubmit,
Expand All @@ -35,14 +35,16 @@ export default function Home() {
<meta name="description" content="contenido saludable" />
</Head>

<Search articles={articles} setArticles={setArticles} handleSubmit={handleSubmit} register={register}/>
<Search articles={articles} setArticles={setArticles} handleSubmit={handleSubmit} register={register} setPage={setPage}/>

<Card articles={articles} />

<Pagination
articles={articles}
getValues={getValues}
setArticles={setArticles}
page={page}
setPage={setPage}
/>
</>
);
Expand Down

1 comment on commit 7e3037e

@vercel
Copy link

@vercel vercel bot commented on 7e3037e Apr 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

challenge-atomik – ./

challenge-atomik.vercel.app
challenge-atomik-nacho93.vercel.app
challenge-atomik-git-main-nacho93.vercel.app

Please sign in to comment.