首页 > 解决方案 > 无法修复未捕获的类型错误:e.target 未定义

问题描述

ReactJS我有一个component如下

<AutoComplete
              style={{ width: 400, fontSize: "13px" }}       
              placeholder="Search for a user"
              options={this.getUserOptions()}
              filterOption={true}
              onSearch={this.handleUserSearch}
              onSelect={this.onSelect}
            />

然后我在搜索中调用一个函数HandleUserSearch

handleUserSearch = (e) => {
    const {value} = e.target
    //do  stuff here
  }

但得到一个

未捕获的类型错误:e.target 是未定义的错误。

有人知道我在做什么错吗?

标签: javascriptreactjstypeerror

解决方案


我相信没有事件传递给 onSearch 函数。对我来说它看起来像 ANTD,所以对于这个函数,值直接传递给参数

handleUserSearch = (value) => {
    const myValue = value; // value is the search criteria string
    //do  stuff here
  }

在此处输入图像描述


推荐阅读