Getting Title and Rating Search Results on Another Page
Explore how to manage search modes in a React movie app by using state variables and useEffect hooks to retrieve paged results for titles or ratings. Learn to reset pagination and fetch the next page of search results depending on the search criteria, enhancing user interaction with movie data.
We'll cover the following...
We'll cover the following...
In this lesson, we’ll learn how to implement the functionality that allows us to return movie results based on title or rating searches for our movie application.
import React from 'react'
import { Switch, Route, Link } from "react-router-dom"
import "bootstrap/dist/css/bootstrap.min.css"
import AddReview from "./components/add-review"
import MoviesList from "./components/movies-list"
import Movie from "./components/movie"
import Login from "./components/login"
import Nav from 'react-bootstrap/Nav'
import Navbar from 'react-bootstrap/Navbar'
function App() {
const [user, setUser] = React.useState(null)
async function login(user = null){// default user to null
setUser(user)
}
async function logout(){
setUser(null)
}
return (
<div className="App">
<Navbar bg="light" expand="lg">
<Navbar.Brand>Movie Reviews</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="mr-auto">
<Nav.Link>
<Link to={"/movies"}>Movies</Link>
</Nav.Link>
<Nav.Link>
{ user ? (
<a onClick={logout}>Logout User</a>
) : (
<Link to={"/login"}>Login</Link>
)}
</Nav.Link>
</Nav>
</Navbar.Collapse>
</Navbar>
<Switch>
<Route exact path={["/", "/movies"]} component={MoviesList}>
</Route>
<Route path="/movies/:id/review" render={(props)=>
<AddReview {...props} user={user} />
}>
</Route>
<Route path="/movies/:id/" render={(props)=>
<Movie {...props} user={user} />
}>
</Route>
<Route path="/login" render={(props)=>
<Login {...props} login={login} />
}>
</Route>
</Switch>
</div>
);
}
export default App;Initial files we will build on
The MoviesList component in the movies-list.js file currently has two modes of retrieval. One is by calling the getAll() function. The other is using the find() ...