vandasche

Untitled

Apr 28th, 2020
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import axios from 'axios';
  4.  
  5. class article extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. book: false,
  10. data: {},
  11. };
  12. }
  13. async componentDidMount() {
  14. const id = this.props.match.params.id;
  15. const article = await axios({
  16. method: 'GET',
  17. url: `http://localhost:5000/api/v1/article/${id}`,
  18. });
  19. this.setState({ data: article.data.data });
  20. console.log(this.state.data);
  21. console.log(this.state.data.User);
  22. }
  23. render() {
  24. const data = this.state.data;
  25. return (
  26. <div>
  27. <h1>Article page</h1>
  28. <h1>{data.title}</h1>
  29. <h3>Author :{}</h3>
  30. <h3>{data.createdAt}</h3>
  31. <h3>{data.description}</h3>
  32. </div>
  33. );
  34. }
  35. }
  36.  
  37. const mapStateToProps = (state) => {
  38. return {
  39. article: state.article,
  40. };
  41. };
  42.  
  43. export default connect(mapStateToProps)(article);
Add Comment
Please, Sign In to add comment