Created
November 14, 2017 09:55
-
-
Save mauricedb/3835457884fbd9fd9bf40578790c1806 to your computer and use it in GitHub Desktop.
Use container & presentation components
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
export default from "./movies-container"; | |
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
import { h, Component } from "preact"; | |
import MoviesPresentation from "./movies-presentation"; | |
class MoviesContainer extends Component { | |
state = { | |
movies: [] | |
}; | |
componentDidMount() { | |
fetch("/api/movies.json") | |
.then(rsp => rsp.json()) | |
.then(movies => this.setState({ movies })); | |
} | |
render({}, { movies }) { | |
return <MoviesPresentation movies={movies} />; | |
} | |
} | |
export default MoviesContainer; |
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
import { h, Component } from "preact"; | |
import style from "./style"; | |
const MoviesPresentation = ({ movies }) => ( | |
<div class={style.movies}> | |
<h2>Movies</h2> | |
<ul>{movies.map(movie => <li>{movie.title}</li>)}</ul> | |
</div> | |
); | |
export default MoviesPresentation; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment