I want to use the package called "youtube-music-api", however I can't get it to work within React. The code resides within a React component that triggers it when the component mounts. The code I used is as follows:
const YoutubeMusicApi = require('youtube-music-api')
function fetchResults(data) {
const api = new YoutubeMusicApi()
api.initalize()
.then(info => {
api.getSearchSuggestions(data).then(result => {
console.log(result)
})
})
}
However, it ends up failing when I try to run it, I receive the following:
I tried using the package outside of React, and it performed successfully. So, I suspect that the issue may be because with React I am serving the page to the user where they then perform the API call. How might I go about using the package within React?
I suggest using the faker.js package. you can easily get fake data according your use case.
import faker from 'faker'
const [data,setData] = useState([])
useEffect(() => {
var randomName = faker.name.findName(); // Rowan Nikolaus
var randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
var randomCard = faker.helpers.createCard(); // {avatar , name etc..}
setData({ name : randomName , email : randomEmai , card : ...randomCard })
},[]);