irom
irom

Reputation: 3596

React componentDidMount does not show axios response

I have React component RandomQouteMachine which is supposed to get response from the provided URL and display it on the page. I don't see response displayed. The debug 'Did component mount ?' message is missing too..

import React, { Component } from 'react';
import axios from 'axios'; 
lass RandomQouteMachine extends Component {
  constructor(props) {
    super(props);

    this.state = {
      data: ""
    };    
  }

  componenetDidMount() {
    console.log('Did component mount ?');
    axios.get('https://api.icndb.com/jokes/random')
      .then((res) => {       
        this.setState({data:res.value.joke});
      })

  }
  render() {
    return (
      <div>
        Here it is:
      {this.state.data}
      </div>
    );
  }
}

export default RandomQouteMachine;

Am I using componenetDidMount() correctly ? I can see only 'Here it is:' displayed on page

Upvotes: 1

Views: 4052

Answers (1)

EJ Mason
EJ Mason

Reputation: 2050

check your spelling.

componenetDidMount !== componentDidMount

Upvotes: 5

Related Questions