在react中,我正在构建一个应用程序。
我有一个问题:
{movies.map((movie) => (
<MovieCard movie={movie} />
))}
</div>
()在=>
直到现在,我一直使用{}after=>
当我使用()时,我的应用程序工作,但如果我使用{},我没有得到任何回报。
我的代码在这里:
const App = () => {
// function doubleNumbers(arr) {
// arr.map(()=>{})
// }
// console.log(doubleNumbers([2, 5, 10]));
const [movies, setMovies] = useState([]);
const [searchTerm, setSearchTerm] = useState("");
useEffect(() => {
searchMovies("batman");
}, []);
const searchMovies = async (title) => {
const response = await fetch(`${API_URL}&s=${title}`);
const data = await response.json();
setMovies(data.Search);
};
return (
<div className="app">
<h1>MovieLand</h1>
<div className="search">
<input
type="text"
placeholder="Search for movies"
// value degistirmeyi nunutmusum yapilir
value={searchTerm}
onChange={(e) => {
setSearchTerm(e.target.value);
}}
/>
<img
src={SearchIcon}
alt="search"
onClick={() => searchMovies(searchTerm)}
/>
</div>
{/* ?. Optional Chaining */}
{movies?.length > 0 ? (
<div className="container">
{/* pk j(utillise ds map () au lieu de {} ??? */}
{movies.map((movie) => (
<MovieCard movie={movie} />
))}
</div>
) : (
<div className="empty">
<h2>No movies found</h2>
</div>
)}
</div>
);
};
export default App;