1 回答

TA貢獻(xiàn)1818條經(jīng)驗 獲得超8個贊
您實(shí)際上并未將文本輸入的值傳遞給提取請求。
我推薦這樣的東西:
class SearchBar extends Component {
searchByKeyword = ({target}) => {
await this.getQuery("story", target.value)
}
async componentDidMount() {
await this.getQuery("story", "butts");
}
getQuery = async(type = "", search_tag = "") => {
var url = "https://hn.algolia.com/api/v1/search?tags=";
const resp = await fetch(`${url}${type}&query=${search_tag}`)
return resp.json()
}
render() {
return (
<input
type="text"
onChange={this.searchByKeyword}
/>
);
}
}
我刪除了狀態(tài)和事物,因為它似乎與問題并不完全相關(guān)。
添加回答
舉報