score:1
Accepted answer
bind the functions in the constructor.
constructor (props) {
super(props);
this.add = this.add.bind(this);
this.somefunc = this.somefunc.bind(this);
}
or use arrow notation (no need for bind)
const add = () => { /* do something */ }
const somefunc = () => { /* do something */ }
<button
onclick={this.add}
>
+1
</button>
update
using both functions in one onclick
const dosomething = (e) => {
add();
somefunc();
}
<button
onclick={this.dosomething}
>
+1
</button>
Source: stackoverflow.com
Related Query
- How to bind two functions to a button click in React
- How to bind two function for a button click in reactjs
- How to implement two or more functions on Click event in React & ES6
- How to navigate on path by button click in react router v4?
- How can I get an input's value on a button click in a Stateless React Component?
- How can I find and click a button that has no text using React Testing Library?
- React Formik bind the external button click with onSubmit function in <Formik>
- How I can disable a button in React js for 5 seconds after click event
- how to add two onClick functions in React
- How to change Cursor Icon upon button click on React
- How to make one table record editable on button click in React when the table record is mapped?
- How to change image on button click with React Hooks?
- How to pass two functions to onClick event in react
- How to add a tab dynamically when we click a button using React js and Bootsrap 4
- How to get the time in seconds after click on submit button using React Count Down Timer
- React how to re-render a placeholder on button click
- How to make react data grid table cell editable and focused on click of a button without performing a double click action
- How to open an <input type="file"/> with a button click in React
- How do I return two functions in a function that renders as two components in react instead of the second function overwriting the first
- How to delete objects from react state hook array with a button click
- how to open datepicker on button click or icon click in react js
- How do I call a function on button click to listen for another mouse click in React Hooks?
- How to animate svg picture after a button click in React
- how to change background color when I click the button using react hooks
- React Js how to jump whole pages to other pages when click on the navigation button
- How to play HTML5 Video in full screen on button click in react js
- How to pass data by button click in redux react js
- React button onClick requires two click to work second time
- How to Create a dropdown Button with see more option and on click toggle should not happen in react js?
- How can click on button to get one of components with react
More Query from same tag
- How to update an array everytime when pushing values
- How to inject `apollo client` through react context via `contextType` instead of consumer?
- How to switch between main, light and dark variances of a Material-UI Palette
- React Button Component doesn't render the label inside the button
- Does a React Native app need read/write permission on Android if using asyncstorage?
- How can i post array of object using axios formik and react js
- error 'propTypes' is not defined and error 'defaultProps' is not defined
- React: onClick on button not working
- Submit button reloads the page
- How can I add a class to a div after a delay based on a state change?
- Many to Many relationships in Redux store
- auth route componentWillMount or DidMount did not trigger when navigate?
- How to pass in an instance variable from a React component to its HOC?
- Formik Field Wrapper
- react-dnd uncaught typerrors. Trying to follow the simple sortable example
- React hook state - does not update component
- My Apache server is displaying a directory listing instead of serving my files -- how do I configure it properly?
- Update state in class from const
- React / TypeScript - Type '{ index:number}' is missing the following properties from type 'IList': length, pop, push, concat, and 26 more
- When should React call AJAX request after props change?
- Weird value bug onChange in React JS
- React Component's inline style is not working
- How to set className for selected child component in ReactJS
- Unable to pause React audio
- document.querySelector CHANGE event?
- How do I wait for a .map() with asynchronous calls to finish before moving on?
- React typescript how to type a hoc
- How can i make required to click one of the toggle buttons in react form?
- Hiding navbar function not working useLocation
- Route is not commited in react