I want to understand how to pass two functions in onChange= when I try to write there check this.check() or even onChange={event => this.check(event)} then the first function does not work as it should, as if Event does not come to her, while alone she works absolutely perfectly there

 import React, {Component} from 'react' import PropTypes from 'prop-types' import CountReducer from '../reducers/CountReducer' import { Link } from 'react-router-dom'; export default class Counter extends Component { constructor(props) { super(props); this.check = this.check.bind(this); } check(event) { this.props.onUpdateClick(event.target.value); this.props.onLink(event.target.value); } render() { const {count, wish_value, onIncreaseClick,onLink,onUpdateClick} = this.props if (count === 1){ return( <div> <div> <span>{count}</span> <button onClick={onIncreaseClick}>Increase</button> <button onClick={onLink}>Поиск</button> <button onClick={onLink}> <Link to="/search">Поиск</Link> </button> <input value={wish_value} type="text" onChange={onUpdateClick} onClick={onLink}/> </div> </div> )} else { return ( <div> <div> <span>{count}</span> <button onClick={onIncreaseClick}>Increase</button> <button onClick={onLink}>Поиск</button> <button onClick={onLink}> <Link to="/" onClick={alert("неверное имя п")}>Поиск</Link> </button> <input value={wish_value} type="text" onChange={onUpdateClick} onClick={onLink}/> </div> </div>) } } } export const updateTodo = (wish_value) => { return { type:'update', wish_value: wish_value } } export const linkTodo = (wish_value) => { return { type: 'link', wish_value: wish_value } } function mapDispatchToProps(dispatch) { return { onIncreaseClick: () => dispatch(actions.increaseTodo()), onLink: () => dispatch(actions.linkTodo()), onUpdateClick: event => dispatch(( actions.updateTodo(event.target.value) )) } 

}

  • did not find, and where check is caused? What event? - Dmitry Kozlov
  • @DmitryKozlov called check instead of onUpdateClick in <input onChange , but it didn’t work there, more precisely it didn’t work onUpdateClick - Ivan Burilichev
  • then onChange={this.check} , and in the onUpdateClick in the check function, you pass a ready-made event.target.value , and inside onUpdateCheck you expect an event and again try to get a target from it. But that line has already arrived - Dmitry Kozlov

1 answer 1

I did it, thanks @DmitryKozlov, the changes I made:

 check(event) { this.props.onUpdateClick(event); this.props.onLink(event.target.value); } <input value={wish_value} type="text" onChange={this.check} onClick={onLink}/>