✨ pagination finished
Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
parent
4427c2efc0
commit
a604592622
1 changed files with 4 additions and 2 deletions
|
@ -12,7 +12,9 @@ function App() {
|
||||||
const [totalPages, setTotalPages] = useState(0)
|
const [totalPages, setTotalPages] = useState(0)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`http://www.omdbapi.com/?apikey=${API_MOVIE_KEY}&s=spider-man`)
|
fetch(
|
||||||
|
`http://www.omdbapi.com/?apikey=${API_MOVIE_KEY}&s=spider-man&page=${currentPage}`
|
||||||
|
)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setMovies(data.Search)
|
setMovies(data.Search)
|
||||||
|
@ -20,7 +22,7 @@ function App() {
|
||||||
})
|
})
|
||||||
.then(() => setLoading(false))
|
.then(() => setLoading(false))
|
||||||
.catch((error) => console.log(error))
|
.catch((error) => console.log(error))
|
||||||
}, [])
|
}, [currentPage])
|
||||||
|
|
||||||
const calculatePages = (totalResults: number): number => {
|
const calculatePages = (totalResults: number): number => {
|
||||||
return Math.round(totalResults / 10)
|
return Math.round(totalResults / 10)
|
||||||
|
|
Reference in a new issue