Created
March 24, 2018 08:18
-
-
Save yaminmhd/c6ba7ccc0f314b2e44f8f1241ecaed48 to your computer and use it in GitHub Desktop.
Stateless components vs functional stateless components vs functional 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
| //Stateless components | |
| import React, {Components} from 'react'; | |
| class Repos extends Component { | |
| render(){ | |
| return ( | |
| <div> | |
| <h3> User Repos </h3> | |
| <ul className="list-group"> | |
| {this.props.repos.map((repo, index) => { | |
| return ( | |
| <li className="list-group-item" key={repo.name}> | |
| <h4><a href={repo.html_url}>{repo.name}</a></h4> | |
| <p>{repo.description}</p> | |
| </li> | |
| ) | |
| })} | |
| </ul> | |
| </div> | |
| ) | |
| } | |
| } | |
| //The repo component will receive an array of repos of specific users, maps over | |
| //those repositories and displays to the view | |
| //Stateless functional components | |
| const Repos = (props) => { | |
| return( | |
| <div> | |
| <h3> User Repos </h3> | |
| <ul className="list-group"> | |
| {props.repos.map((repo, index) => { | |
| return ( | |
| <li className="list-group-item" key={repo.name}> | |
| <h4><a href={repo.html_url}>{repo.name}</a></h4> | |
| <p>{repo.description}</p> | |
| </li> | |
| ) | |
| })} | |
| </ul> | |
| </div> | |
| ) | |
| } | |
| //stateless functional components is a function with props being passed as your first | |
| //argument | |
| //Functional components | |
| const RepoWithState = () =>{ | |
| //future functional components will have their own state | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment