Currently, the console.log()
in makeQuery()
is returning the correct object while the console.log()
in scoop()
is returning "undefined" as the definition of response
in scoop()
is not waiting for the function call to makeQuery()
to return.
I would like for the definition of response
in scoop()
to wait for the function call to makeQuery()
before the code below runs.
How do I make this happen?
var request = require('request');
const makeQuery = (query) => {
request('http://0.0.0.0:4000/wikiweb?text=' + query, function (error, response, body) {
var jason = JSON.parse(body)
console.log(jason)
return jason
}
)
class Wiki extends React.Component {
constructor (props) {
super(props)
this.scoop = this.scoop.bind(this);
this.state = {loaded: false}
}
scoop = async (e) => {
e.preventDefault();
var query = this.textInput.value;
var response = await makeQuery(query);
console.log(response)
// await this.setState({data : response, loaded : true});
// console.log(this.state.data)
}
...