skip to Main Content
componentDidMount() {
  const wordpressSiteUrl = 'http://projects.stagingsoftware.com/quacito_new/blog';
  this.setState(stats: { loading: true }, callback: () => {
  axios.get(url: `${wordpressSiteUrl}/wp-json/wp/v2/posts`)
 });
}

I want wordpress blog fetch in react js but I’m unable that

2

Answers


  1. This is the correct syntax:

    this.setState({ stats: { loading: true } }, () => {
        axios.get(`${wordpressSiteUrl}/wp-json/wp/v2/posts`);
    });
    
    Login or Signup to reply.
  2. You need to do it just like this. Just add curly brackets {} in setState and axios.

    componentDidMount() { 
        const wordpressSiteUrl = 'http://projects.stagingsoftware.com/quacito_new/blog'; 
        this.setState({stats: { loading: true }, callback: () => { axios.get(url=` ${ wordpressSiteUrl }/wp-json/wp/v2/posts`) }}); 
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search