Created
March 6, 2020 16:25
-
-
Save faahmad/bd2590db6fdeadf11d6e4287fd7c2f0a to your computer and use it in GitHub Desktop.
Opinionated React 3: State Management
This file contains hidden or 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
| const MovieList: React.FC = () => { | |
| const [isLoading, setIsLoading] = React.useState<boolean>(true) | |
| const [movies, setMovies] = React.useState<Movie[]>([]) | |
| React.useEffect(() => { | |
| MovieService | |
| .fetchInitialMovies() | |
| .then(initialMovies => setMovies(initialMovies)) | |
| .then(() => setIsLoading(false)) | |
| }, []) | |
| if (isLoading) { | |
| return <div>Loading movies...</div> | |
| } | |
| return ( | |
| <ul> | |
| {movies.map(movie => <li key={movie.id}>{movie.title}</li>} | |
| </ul> | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment