First one . This is React - if you ever find yourself using jQuery, you are probably wrong.
( ), , , . , , , . .
. , , . , ctrl + 1 , - - . eventListener , .
class Application extends React.Component {
constructor(props) {
super(props)
this.addSection = this.addSection.bind(this)
this.keydownHandler = this.keydownHandler.bind(this)
}
componentDidMount() {
document.addEventListener('keydown', this.keydownHandler)
}
componentWillUnmount() {
document.removeEventListener('keydown', this.keydownHandler)
}
addSection() {
alert("add section")
}
keydownHandler(event) {
if(event.keyCode===49 && event.ctrlKey)
this.addSection()
}
render() {
return (
<div>
<p>Press Ctrl+1</p>
</div>
)
}
}
CodePen.
:
toolbar.js:
import React, { Component } from 'react';
class Toolbar extends Component {
constructor(props) {
super(props)
this.addSection = this.addSection.bind(this)
this.keydownHandler = this.keydownHandler.bind(this)
}
componentDidMount() {
document.addEventListener('keydown', this.keydownHandler)
}
componentWillUnmount() {
document.removeEventListener('keydown', this.keydownHandler)
}
addSection() {
alert("add section")
}
keydownHandler(event) {
if(event.keyCode===49 && event.ctrlKey)
this.addSection()
}
render(){
return (
<div className="toolbar">
<button onClick={this.addSection.bind(this)}>add section</button>
</div>
)
}
}
export default Toolbar;
main.js:
import React from 'react'
import ReactDOM from 'react-dom'
import Toolbar from './components/toolbar'
const App = () => {
return (
<div>
<Toolbar />
</div>
)
}
Meteor.startup(() => {
ReactDOM.render(<App />, document.querySelector('.container'))
})
. , React, jQuery, , , . , , , , , React , . , jQuery, React, ( , shhh... ). , , , jQuery, React.
. StackOverflow , . , Meteor Forums . . - Reactiflux, Acemarke ( ) - , - , Facebook React ( , , ).
, ( ) - . . , . , .