I have a question how to tell useEffect to wait for text which comes from search input?
API contains lots of objects and i want to fetch one of them .
import React, { useState, useEffect } from 'react';
import axios from 'axios';
const Search = () => {
const [text, setText] = useState('');
const [object, setObject] = useState(null);
useEffect(() => {
axios.get(`https://api/${text}`)
.then(res => {
setObject(text)
console.log(object)
})
.catch(err => {
console.log(err)
})
})
const onChange = e => setText(e.target.value);
return (
<div>
<form className="some-class">
<input type="text" value={name} className="some-class" placeholder="I need information about..." onChange={onChange}/>
<input type="submit" className="some-class" value="Search"/>
</form>
</div>
)
}
export default Search;