1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-electron/renderer/pages/start.js
Sergio Xalambrí 4b0467ed42 Add Electron example (#1430)
* Add Electron usage example

* Remove the deploy part

* Only allow GET request to our HTTP server

* Only allow request from an electron app (checking the user agent)

* Add warning about the local HTTP server

* Update package.json

* Update example to use Next.js v3

* Added required package.json fields with placeholders

* Use next:// file protocol to open internal built files

* Create next.config.js

* Update set-menu.js

* Update example to merge it with electron-next-skeleton ideas
2017-08-09 07:56:23 +02:00

58 lines
1.2 KiB
JavaScript

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>
)
}
}