Hello all here im doing practice of react. I created react app which has a search bar and clickable button. When i submit the data it can fetch users data from "https://www.drupal.org/search/user/" site. but here i can't fetch data from the site.
import React, { Component } from 'react'
import axios from 'axios';
class Search extends Component {
state = {
name: ''
};
handleChange = event => {
this.setState({ name: event.target.value });
}
handleSubmit = event => {
alert("Hello Im : " + this.state.name);
event.preventDefault();
const user = {
name: this.state.name
};
axios.post(`https://www.drupal.org/search/user/`, { user })
.then(res => {
console.log(res);
console.log(res.data);
})
}
render() {
return ( < >
<div > < h1 > Search here < /h1>< /div >
<form onSubmit = { this.handleSubmit } align = "center" >
<input type = "search" name = "name" onChange = { this.handleChange } placeholder = "Search" required / >
<button type = "submit" >Search < /button >
< /form >
</>);
}
}
export default Search;