I have a sidebar with a canvas animation which is created based on the size of the window.

```
componentDidMount() {
    let styles = window.getComputedStyle(this.sidebar.current)
    let w = styles.width
    let h = styles.height
    console.log("getComputedStyle:", styles.height, styles.width)
    this.setState({ "isOn": true, "height": h, "width": w })
}

```

My question is how could the state change according to window size change? I am trying to add a window.onresize function, but I don't know how to pass the component and states.