Skip to content

Instantly share code, notes, and snippets.

@mauricedb
Created November 14, 2017 09:55
Show Gist options
  • Save mauricedb/3835457884fbd9fd9bf40578790c1806 to your computer and use it in GitHub Desktop.
Save mauricedb/3835457884fbd9fd9bf40578790c1806 to your computer and use it in GitHub Desktop.
Use container & presentation components
export default from "./movies-container";
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;
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