Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import { connect } from 'react-redux';
- import axios from 'axios';
- class article extends Component {
- constructor(props) {
- super(props);
- this.state = {
- book: false,
- data: {},
- };
- }
- async componentDidMount() {
- const id = this.props.match.params.id;
- const article = await axios({
- method: 'GET',
- url: `http://localhost:5000/api/v1/article/${id}`,
- });
- this.setState({ data: article.data.data });
- console.log(this.state.data);
- console.log(this.state.data.User);
- }
- render() {
- const data = this.state.data;
- return (
- <div>
- <h1>Article page</h1>
- <h1>{data.title}</h1>
- <h3>Author :{}</h3>
- <h3>{data.createdAt}</h3>
- <h3>{data.description}</h3>
- </div>
- );
- }
- }
- const mapStateToProps = (state) => {
- return {
- article: state.article,
- };
- };
- export default connect(mapStateToProps)(article);
Add Comment
Please, Sign In to add comment