Reputation: 5566
I have a simple react component for my app, I would like to add resize function using window add event listener
Here is my solution
import React, { Component } from 'react';
class thankyoupayment extends Component {
const resizeWindow = () =>{
console.log('Resize me');
}
componentDidMount() {
window.addEventListener('resize', this.resizeWindow);
}
render() {
return (
<VideoContainer>
<video></video>
</VideoContainer>
);
}
}
const VideoContainer =styled.div`
display: flex;
justify-content: center;
`
Unfortunately when I run I am gettin the following error
Unexpected token (8:10)
What do I need to change to solve the problem? React Newbie as hell
Upvotes: 0
Views: 1184
Reputation: 41893
First of all, the Class name should be capitalized:
class Thankyoupayment extends Component {
Secondly, you can't use const
as a Class method:
resizeWindow = () => {
Upvotes: 1