I am trying to learn react by practising a simple problem.
I followed the below youtube tutorial
https://www.youtube.com/watch?v=AsvybgZTryo&list=PLKhlp2qtUcSZiWKJTi5-5r6IRdHhxP9ZU&index=17
but when I search for an item the item is not passing properly in the api call
https://dummyjson.com/users/search?q=${searchTerm}
can you let me know what is the issue, providing the codse snippet and stackblitz below
useEffect(() => {
const fetchUsers = () => {
if (searchTerm.trim() === '') {
setSuggestions([]);
return;
}
fetch('https://dummyjson.com/users/search?q=${searchTerm}')
.then((res) => {
res.json();
})
.then((data) => setSuggestions(data))
.catch((err) => {
console.log('error', err);
});
};
fetchUsers();
}, [searchTerm]);