Just trying to get these videos to play on mouse over. I can see from the console I need to make a function instead of using a string (other SO answers use strings), so how can I do this without creating too much extra code? Ideally I want the functions set right on the onMouseOver & onMouseOut attributes.
<video
poster="https://i.imgur.com/Us5ckqm.jpg"
onMouseOver="this.play()"
onMouseOut="this.pause();this.currentTime=0;"
src={`${vid.videos.tiny.url}#t=1`}
</video>
Have also tried
<video
poster="https://i.imgur.com/Us5ckqm.jpg"
onMouseOver={() => this.play()}
onMouseOut={() => this.pause()}
src={`${vid.videos.tiny.url}#t=1`} >
</video>
Which gives me the error: Cannot read property 'play' of undefined.
Edit Not sure this is relevant, but this code above resides inside of a map function, which is also part of a get request. Here is the full function:
const fetchVideos = async (amount, category) => {
const response = await axios.get('https://pixabay.com/api/videos/', {
params: {
key: '123456123456123456',
per_page: amount,
category: category
}
})
console.log(response)
const vidsAsHtml = response.data.hits.map(vid => {
return (
<div className={`${props.page}--grid-content-wrapper`} key={vid.picture_id}>
<div className={`${props.page}--grid-video`}>
<video className=".video"
poster="https://i.imgur.com/Us5ckqm.jpg"
onMouseOver={() => this.play()}
onMouseOut={() => this.pause()}
src={`${vid.videos.tiny.url}#t=1`} >
</video>
</div>
<div className={`${props.page}--grid-avatar-placeholder`}></div>
<div className={`${props.page}--grid-title`}>{vid.tags}</div>
<div className={`${props.page}--grid-author`}>{vid.user}</div>
<div className={`${props.page}--grid-views`}>{abbreviateNumbersOver999(vid.views)}
<span className={`${props.page}--grid-date`}> • 6 days ago</span>
</div>
</div>
)
})
setResource(vidsAsHtml)
}
Edit 2: Seems like some other people had problem with the 'this' keyword inside of mapping statement. Although I tried these solutions and 'this' is still undefined.