Soy nuevo en reaccionar y necesito aprender algunas cosas. Necesito saber si mi forma de obtener una película específica es correcta (funciona, pero creo que no es la forma correcta). Tengo un estado de datos. Necesito obtener un objeto específico. dentro de la matriz y este objeto se mostrará en el componente "spesificMovie", así que para obtener el objeto correcto, creo una función que se ejecuta con filtro en el estado con datos y luego busca si el nombre es igual al nombre que le doy a la función como argumento. devolverá el objeto a otro estado que será spesificMovie y este estado lo muevo al componente spesificMoive
import { useState } from "react"; import Movie from "./componente/Movie"; import SpesificMovie from "./componente/SpesificMovie"; function App() { const [spesificMovie, setSpesificMovie] = useState(); const getMovieFunc = (name) => { movies.filter((movie) => { if (movie.movieName == name) return setSpesificMovie(movie); }); }; const [movies, setMovies] = useState([ { movieName: "godfather", info: "the rise of corelone family all mater is respect,money,woman but the youngest son michal has a diffrent plans...", picture: "pictures/godfather.jpg", rating: [10, 5, 1], }, { movieName: "scarface", info: "the rise of tony montata the badass man of miami want to control miami and be the number 1 of the cocaine provider ...", picture: "pictures/scarface.jpg", rating: [10, 9, 2], }, { movieName: "the-dark-knight", info: "you all knew that he will come the batman! come to fight with his popular rival the joker...", picture: "pictures/the-dark-knight-poster.jpg", rating: [10, 10, 9], }, ]); return ( <div className="App"> <SpesificMovie spesificMovie={spesificMovie}/> <Movie movies={movies} getMovieFunc={getMovieFunc}/> </div> ); } export default App;