forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
57 lines (47 loc) · 1.2 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 (
<div>
<h1>Hello Electron!</h1>
{this.state.message &&
<p>{this.state.message}</p>
}
<form onSubmit={this.handleSubmit}>
<input type='text' onChange={this.handleChange} />
</form>
<style jsx>{`
h1 {
color: red;
font-size: 50px;
}
`}</style>
</div>
)
}
}