I'm building a web page that uses fetch to search information and it shows it to the user.
I've decided to store that information in a state but for some reason it doesn't work the way I expected.
When the data arrives I use setText() and then I print both the 'text' and 'data' variables.
Only 'data' is printing something, 'text' doesn't show anything.
Anyone knows what can be the problem here?
const [text, setText] = useState("")
const getTextFromApi = async () => {
const resp = await fetch(endpoint)
const data = await resp.json()
setText(data)
console.log(data)
console.log("------------------------")
console.log(text)
}