Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created July 23, 2018 13:41
Show Gist options
  • Save azamsharp/04de4405a0239098e11d043364d5900f to your computer and use it in GitHub Desktop.
Save azamsharp/04de4405a0239098e11d043364d5900f to your computer and use it in GitHub Desktop.
MovieList
import React, {Component} from 'react'
import {Link} from 'react-router-dom'
export class MovieList extends Component {
constructor(props) {
super(props)
this.state = {
movies : []
}
}
componentDidMount() {
let movies = ["Lord of the Rings", "Taxi", "Margin Call"]
this.setState({
movies : movies
})
}
render() {
let movieItems = this.state.movies.map((movie,index) => {
let newObj = {
pathname : `/movies/${index}`,
movie : {
name : movie,
movieId : index
}
}
return (
<li key = {index}><Link to={`/movies/${index}`}> {movie} </Link> </li>
)
})
return (
<ul>{movieItems}</ul>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment