Currently experimenting with the Github user API to understand how things function before incorporating it into a project. However, I've encountered an issue.
const btn = document.querySelector('button') as HTMLButtonElement
const input = document.querySelector('input') as HTMLInputElement
const USER_API: string = 'https://api.github.com/users/callmenikk'
const fetchData = async () => {
const fetchUser = await fetch(USER_API)
const userData = fetchUser.json()
userData.then(resolve => console.log(resolve))
}
btn.addEventListener('click', fetchData)
With this code snippet, my goal is to display my personal user data in the console. However, when executed, it reloads the page and adds a question mark at the end of the link such as http://localhost:3000/?
. The JSON output is not displayed in the console. Strangely, if I remove the EventListener, the function works correctly. What could I be doing incorrectly?