ES6 React.Component
doesn’t auto bind methods to itself. You need to bind them yourself in constructor
. Like this:
constructor (props){
super(props);
this.state = {
loopActive: false,
shuffleActive: false,
};
this.onToggleLoop = this.onToggleLoop.bind(this);
}
More Related Contents:
- “this” is undefined inside map function Reactjs
- TypeError: Cannot read property ‘setState’ of undefined
- How to bind onclick handlers to `this` properly on React
- How does event handlers with arrow functions achieve context binding
- When to use ES6 class based React components vs. functional ES6 React components?
- Why and when do we need to bind functions and eventHandlers in React?
- React-Router: No Not Found Route?
- What is the right way to use Jquery in React?
- Error: [PrivateRoute] is not a component. All component children of must be a or
- What is the difference between React Native and React?
- React JSX: selecting “selected” on selected option
- React.js: Set innerHTML vs dangerouslySetInnerHTML
- ReactJS SyntheticEvent stopPropagation() only works with React events?
- this operator in javascript
- react.js Replace img src onerror
- React | How to detect Page Refresh (F5)
- How to handle calling functions on data that may be undefined?
- First Load JS shared by all is rather heavy in next.js
- Why is React not rendering my component state correctly?
- I can’t reference an image in Next.js
- Is there a way to render multiple React components in the React.render() function?
- Do we still need functional setState way in react hooks?
- React 18 strict mode causing component to render twice [duplicate]
- Reactjs-setState previous state is the first argument, props as the second argument
- Uncaught Invariant Violation: Rendered more hooks than during the previous render
- How to mock React component methods with jest and enzyme
- JavaScript this refers to window instead of object inside function
- Deep nested array of objects not rendering
- create-react-app is showing all my code in production, how to hide it?
- Why would we use useEffect without a dependency array?