handlesubmit is not a function grocery list

  //fetch data from server
  handleData = () => {
    fetch('http://localhost:5000/api/listitems')
       .then(response => response.json())
       .then(data => this.setState({ items: data }));
  }

  //call handleData() on page load
  componentDidMount() {
    this.handleData();
  }

  //this function fires when form is submited
  handleSubmit(event) {
    event.preventDefault();
    fetch('http://localhost:5000/api/listitems', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
     body: JSON.stringify( {
        Content: this.state.content,
        List_Group: this.state.listgroup,
        Date_Added: this.state.date
      })
    })
    .then(res => res.json())
    .then(() => this.setState({content: ''}))
    //call handleData() when form is submited, which reloads list
    .then(() => this.handleData())
    .then(console.log(this.state.items))
    .catch(err => console.log(err));
  }  

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source