Guest User

Untitled

a guest
Oct 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class Topics extends React.Component {
  2.  
  3. constructor(props){
  4. super(props);
  5. this.state ={
  6. url:props.match.url,
  7. path:props.match.path
  8. }
  9. }
  10. render(){
  11.  
  12. return (<div>
  13. <h2>Topic</h2>
  14. <ul>
  15. {topics.map(({ name, id }) => (
  16. <li key={id}>
  17. <Link to={`${this.state.url}/${id}`}>{name}</Link>
  18. </li>
  19. ))}
  20. </ul>
  21. <Route path={`${this.state.path}/:topicId`} component={TopicDetails}/>
  22. </div>)
  23.  
  24. }
  25. }
  26.  
  27. const TopicDetails = ({match}) => {
  28. const topic = topics.find(({ id }) => id === match.params.topicId);
  29.  
  30. return (<div>
  31. <h2>Details</h2>
  32. <h2>{topic.name}</h2>
  33. <p>{topic.description}</p>
  34.  
  35. </div>
  36. )
  37.  
  38. }
  39.  
  40.  
  41. export default TopicDetails;
Add Comment
Please, Sign In to add comment