btholt / complete-intro-to-react-v6

learn React.js with Brian Holt
https://frontendmasters.com/courses/complete-react-v6/
Other
1.47k stars 215 forks source link

Unable to fetch breeds data from Pet api #35

Closed divakar54 closed 3 years ago

divakar54 commented 3 years ago

I am unable to fetch breeds data from the Pets api. const res = await fetch( http://pets-v2.dev-apis.com/breeds?animal=${animal} ); the above line returns, { "animal": "${animal}" }

veeraraghavan commented 3 years ago

@divakar54 I think the issue is because the request being fired is http://pets-v2.dev-apis.com/breeds?animal=${animal} as opposed to http://pets-v2.dev-apis.com/breeds?animal=dog This is because the template string has not been replaced ${animal} . Are you using the template literal `

const res = await fetch(`http://pets-v2.dev-apis.com/breeds?animal=${animal}`);

divakar54 commented 3 years ago

I am using the template literal, but the problem got solved anyway. I was doing a small mistake somewhere else, the url works fine.