简体   繁体   中英

How to debug: Change from div to form element in React. No response

I try to change from div to form element (to use the type="submit" ) in the react render but there's no response. It shows http://localhost:3000/ ? FYI, div is working fine. The code is as below:

<div className="SearchBar">
 <input placeholder="Enter A Song, Album, or Artist" onChange={this.handleTermChange} />
 <a onClick={this.handleSearch}>SEARCH</a>
</div>

===

<form className="SearchBar" onSubmit={this.handleSearch}>
 <input placeholder="Enter A Song, Album, or Artist"  onChange={this.handleTermChange} />
 <button type="submit">SEARCH</button>
</form>

The Github repo is here .

Thank you for your time.

Probably your submit is giving refresh on the screen.

Use an e.preventDefault () at the beginning of your function its handleSearch function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM