首页 > 解决方案 > 函数返回组件

问题描述

对于我的应用程序,我想放置一个表单,在提交时会显示一些信息。

这是我所做的:

应用程序.js

class App extends Component {

  constructor(props){
    super(props);
    this.search= this.search.bind(this);
  };

  handleInputChange = (event) => {
    let input = event.target;
    let name = event.target.name;
    let value = input.value;
    this.setState({[name]: value})
  };

  async search(event){
    event.preventDefault);
    const searchNumber = this.state.search;
    const getOrderInventoryList = ...
    return (<p>Order inventory list: {getOrderInventoryList }</p>)
  };

  render(){
    return(
      <div className='App'>
        <form onSubmit={this.search}>
          <input name='search' type='text' required 
                 onChange={this.handleInputChange}/>
        </form>
        {this.search}
      </div>
    );
  }
}

我已经用 console.log 验证了搜索功能正在运行,但我无法让它返回...我已经尝试了一些东西,但我不知道我在哪里出错了:/。

所以我想请求一些帮助。

我提前感谢任何愿意花时间帮助我的人。

标签: javascriptreactjsevent-handlingasync.jsreact-component

解决方案


推荐阅读