import { Component } from 'react' import { ipcRenderer } from 'electron' export default class extends Component { state = { input: '', message: null } componentDidMount () { // start listening the channel message ipcRenderer.on('message', this.handleMessage) } componentWillUnmount () { // stop listening the channel message ipcRenderer.removeListener('message', this.handleMessage) } handleMessage = (event, message) => { // receive a message from the main process and save it in the local state this.setState({ message }) } handleChange = event => { this.setState({ input: event.target.value }) } handleSubmit = event => { event.preventDefault() ipcRenderer.send('message', this.state.input) this.setState({ message: null }) } render () { return (

Hello Electron!

{this.state.message &&

{this.state.message}

}
) } }