Q: Electron ipcRenderer events in a React class component I am using Electron with React and I am facing a little problem.
I trigger an event (ipcRenderer.send) in component's willMount method and listen for the response (ipcRenderer.on) in component't didMount method.
But I get a warning in the console (see below) when i try to setState in the listener.
warning.js:35 Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component.
Here is the code:
    import {remote, ipcRenderer} from 'electron';
    import React from 'react';
    import ListItem from './ListItem';

    constructor(props) {
     super(props);
     this.state = {
      packages: []
     }
     this.updatePackages = this.updatePackages.bind(this);
    }

    updatePackages(packages) {
      this.setState({
        packages: packages
      });
    }

    componentWillMount() {
     ipcRenderer.send('get-global-packages');
    }

    componentDidMount() {
     ipcRenderer.on('get-global-packages-reply', (event, packages) => 
     {
      this.updatePackages(packages);
     });
    }

    componentWillUnmount() {
     ipcRenderer.removeAllListeners(['get-global-packages-reply');
    }

    render() {
     let packages = this.props.packages;
     if(!packages) {
      return null;
     }
     return (
      <div className="packages-list" ref={(el) => {
        this.list = el;
       }}/>
       {packages.map((pkg, idx) => {
         return <ListItem key={idx} {...pkg}/>
       })}
      </div>
     )
    }

I have read the related post ipcRenderer in React component constructor
where he uses ref which i did, but now the root variable is null,
this means to me that the component is not mounted.
updatePackages(packages) {
 let root = this.list;
 if(root) {
  this.setState({
   packages: packages
  });
 }
}

What can I do to clear the warning or use the ref prop correctly?
related project repo):
https://github.com/rvpanoz/luna
Thanks in advance.
