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) )) } }
checkinstead ofonUpdateClickin<input onChange, but it didn’t work there, more precisely it didn’t workonUpdateClick- Ivan BurilichevonChange={this.check}, and in theonUpdateClickin thecheckfunction, you pass a ready-madeevent.target.value, and insideonUpdateCheckyou expect aneventand again try to get atargetfrom it. But that line has already arrived - Dmitry Kozlov