JavaScript “Function is not defined” onClick function inline of a component in ReactJs?

I have create come component in reactJs, consist of 2 button which handle each onClick function, But when I run the code "myfunction is not defined" error is appear. I want to redirect page to specified address when button triggered. Whats wrong with my code?

import React, { Component } from 'react';
import { Link } from 'react-router-dom';

class MainMenu extends React.Component {
  constructor(props){
    super(props);
    this.slotClick = this.slotClick.bind(this);
    this.freqClick = this.freqClick.bind(this);
  }
   slotClick = (e) => {
    e.preventDefault();    
  }
   freqClick = (e) => {
    e.preventDefault();
  }
  render() {
    return (
      <div>   
        <input type="button" value="By Time Slot" onClick={ slotClick } />
        <input type="button" value="By Frequency" onClick={ freqClick } />
      </div>
    )
  }
}

export default MainMenu;
Answer:1

You need to access the functions from this. And also you don't need to bind() because the functions are Arrow Functions.

render() {
    return (
      <div>   
        <input type="button" value="By Time Slot" onClick={ this.slotClick } />
        <input type="button" value="By Frequency" onClick={ this.freqClick } />
      </div>
    )
  }
Answer:2

I would like to volume mount a directory from a Docker container to my work station, so when I edit the content in the volume mount from my work station it updated in the container as well. It would ...

I would like to volume mount a directory from a Docker container to my work station, so when I edit the content in the volume mount from my work station it updated in the container as well. It would ...

So, the parent class Select declares this.elem as a DOM-element <select> and this.value, that links to a value of selected option class Select { constructor(classList, isTwoLevel, index){ ...

So, the parent class Select declares this.elem as a DOM-element <select> and this.value, that links to a value of selected option class Select { constructor(classList, isTwoLevel, index){ ...

The whole idea is to take users input in a form and display their input in a JSON object. In state I have an array and inside it another array. My Form.js looks like this, state= { groups:[{ ...

The whole idea is to take users input in a form and display their input in a JSON object. In state I have an array and inside it another array. My Form.js looks like this, state= { groups:[{ ...

In componentDidMount I'm trying to get data called topic from /api/topics/${params.TopicId route then from response I want to send only topic.user_id to another route and get whole user as response. ...

In componentDidMount I'm trying to get data called topic from /api/topics/${params.TopicId route then from response I want to send only topic.user_id to another route and get whole user as response. ...

  1. getting data from api
  2. getting data from firestore
  3. getting data from twitter
  4. getting data from a dead phone
  5. getting data from old hard drive
  6. getting data from json
  7. getting data from firebase
  8. getting data from android to iphone
  9. getting data from another sheet in excel
  10. getting data from google analytics
  11. getting data from excel in python
  12. getting data from figure matlab
  13. getting data from instagram
  14. getting data from api python
  15. getting data from broken iphone
  16. getting data from json javascript
  17. getting data from a dead computer
  18. getting data from multiple tables sql
  19. getting data from snapchat
  20. getting data from api react