Reactjs 同一事件的多次调用

Reactjs 同一事件的多次调用,reactjs,ecmascript-6,Reactjs,Ecmascript 6,我正在对同一事件调用两个函数onChange 但是第二个不是很可爱this.updateValue 输入的值不会改变 ---->但是如果我们删除第一个呼叫并将其更改为 --->onChange={this.updateValue}:输入上的值发生了变化,这表明在同时调用两个函数时出现了问题 import React from 'react' class SearchBar extends React.Component { constructor(props) {

我正在对同一事件调用两个函数
onChange
但是第二个不是很可爱
this.updateValue
输入的值不会改变 ---->但是如果我们删除第一个呼叫并将其更改为 --->
onChange={this.updateValue}
:输入上的值发生了变化,这表明在同时调用两个函数时出现了问题

import React from 'react'

class SearchBar extends React.Component
{
    constructor(props)
    {
        super(props)
        this.state = {input_value : ''}
    }
    updateValue = (event) =>
    {
        this.setState({input_value : event.target.value})
    }

    render()
    {
        return(
            <React.Fragment>
            <input 
                type="text" 
                value={this.state.input_value} 
                onChange={() => (this.props.toChild(this.state.input_value,this.updateValue))}
            />
            </React.Fragment>
        )
    }
}
export default SearchBar
从“React”导入React
类SearchBar扩展了React.Component
{
建造师(道具)
{
超级(道具)
this.state={input_值:“”}
}
updateValue=(事件)=>
{
this.setState({input_value:event.target.value})
}
render()
{
返回(
(this.props.toChild(this.state.input_值,this.updateValue))}
/>
)
}
}
导出默认搜索栏

一个函数将在
onChange
上执行。你可以做以下事情

// prop to input in render
onChange={this.updateValue}
// In function
updateValue = (event) =>
{
    this.props.toChild(event.target.value)
    this.setState({input_value : event.target.value})
}

一个函数将在
onChange
上执行。你可以做以下事情

// prop to input in render
onChange={this.updateValue}
// In function
updateValue = (event) =>
{
    this.props.toChild(event.target.value)
    this.setState({input_value : event.target.value})
}