Last active
May 30, 2021 05:06
-
-
Save moonformeli/485ffe8de335bb7507d1ac9f33d05302 to your computer and use it in GitHub Desktop.
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
interface Movie { | |
title: string; | |
} | |
interface Director { | |
name: string; | |
age: number; | |
} | |
interface Actor { | |
code: id; | |
name: string; | |
age: number; | |
movies: Movie[]; | |
} | |
interface MoviePayload { | |
title: string; | |
director: Director; | |
actors: Actor[]; | |
} | |
async function getMovie(id: string) { | |
return await Controller.getMovie(id); | |
} | |
function MovieDetail(id) { | |
const [movie, setMovie] = useState(null); | |
const fetchMovie = async id => { | |
const payload = await getMovie(id); | |
setMovie(payload); | |
} | |
return ( | |
<section> | |
<div> | |
<button onClick={() => fetchMovie("2021")}>Fetch Movie</button> | |
</div> | |
{movie && ( | |
<MovieInfo> | |
<Title>{movie.title}</Title> | |
<Director>{movie.director}</Director> | |
<Actors> | |
{movie.actors.map(actor => ( | |
<Actor key={actor.code}>{actor.name}</Actor> | |
))} | |
</Actors> | |
</MovieInfo> | |
)} | |
</section> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment