-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87949d9
commit bdd874d
Showing
5 changed files
with
150 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import axios from "axios"; | ||
|
||
const searchForArticles = async ({ article, relevant }) => { | ||
const data = {}; | ||
const params = {}; | ||
try { | ||
if (relevant) { | ||
params = { | ||
search: article, | ||
orderby: relevant, | ||
}; | ||
} else { | ||
params = { | ||
search: article, | ||
}; | ||
} | ||
data = await axios({ | ||
method: "get", | ||
url: `https://beta.mejorconsalud.com/wp-json/mc/v3/posts?`, | ||
params: { | ||
...params, | ||
}, | ||
responseType: "json", | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
|
||
return data; | ||
}; | ||
|
||
const getAllLastArticles = async () => { | ||
const data = {}; | ||
try { | ||
data = await axios({ | ||
method: "get", | ||
url: `https://beta.mejorconsalud.com/wp-json/mc/v3/posts?`, | ||
params: { | ||
orderby: "date", | ||
order: "desc", | ||
}, | ||
responseType: "json", | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
return data; | ||
}; | ||
|
||
export { searchForArticles, getAllLastArticles }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useState, useEffect, useRef } from "react"; | ||
|
||
export const useFetch = (url) => { | ||
const isMounted = useRef(true); | ||
const [state, setState] = useState({ | ||
data: null, | ||
loading: true, | ||
error: null, | ||
}); | ||
|
||
useEffect(() => { | ||
return () => { | ||
isMounted.current = false; | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
setState({ data: null, loading: true, error: null }); | ||
|
||
fetch(url) | ||
.then((resp) => resp.json()) | ||
.then((data) => { | ||
if (isMounted.current) { | ||
setState({ | ||
loading: false, | ||
error: null, | ||
data, | ||
}); | ||
} | ||
}) | ||
.catch(() => { | ||
setState({ | ||
loading: false, | ||
error: "no hay datos", | ||
data: null, | ||
}); | ||
}); | ||
}, [url]); | ||
|
||
return state; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bdd874d
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.
Successfully deployed to the following URLs:
challenge-atomik – ./
challenge-atomik-git-main-nacho93.vercel.app
challenge-atomik.vercel.app
challenge-atomik-nacho93.vercel.app