function runOnKeys(func, ...codeN){
var pressed = [];
window.onkeydown = function(e){
pressed.push(e.which);
for(var i = 0; i<codeN.length; i++){
if(pressed.indexOf(codeN[i]) == -1) return false;
}
func();
pressed = [];
}
window.onkeyup = function(e){
pressed = [];
}
}
runOnKeys(
function() { alert("Привет!") },
"Q".charCodeAt(0),
"W".charCodeAt(0)
);
createCheckboxes = () => {
const data = this.props.pets[0] || {};
const newAnimals = Object.values(data).map(el => el.animal);
this.setState(({ animals }) => ({
animals: [ ...animals, ...newAnimals ],
}));
};
let counterReducer = (state=initialState, action) => {
let newstate = { ...state };
switch(action.type){
case "INC":
newstate.counter+=action.payload
return newstate
case "DEC":
newstate.counter+=action.payload
return newstate
default:
return newstate
}
}
class Header extends Component {
state = {
headerClass: headerClass(),
headerSticky: headerSticky(),
};
componentDidMount() {
window.addEventListener('scroll', this.handleScroll);
};
componentWillUnmount() {
window.removeEventListener('scroll', this.handleScroll);
};
handleScroll = e => {
this.setState({
headerSticky: headerSticky(),
});
};
render() {
...
}
}
import { applyContainerQuery } from 'react-container-query';
import { First, Second, Wrapper } from '../somePlace';
const myQuery = {
hasMinWidth: {
minWidth: 1024,
},
};
class MyComponent extends Component {
...
render() {
const {
containerQuery: { hasMinWidth },
} = this.props;
return (
<Wrapper>
{hasMinWidth ? <First /> : <Second />}
</Wrapper>
);
}
}
export default applyContainerQuery(MyComponent, myQuery);
GET '/api/v1/animals?page=1&limit=20sort=name&sortDirection=DESC&priceFrom=1000&priceTo=2000'
class UserForm extends React.Component{
state = {
login: '',
password: '',
};
handleChange = e => {
const { name, value } = e.target;
this.setState({
[name]: value,
});
};
handleSubmit = e => {
const { login, password } = this.state;
e.preventDefault();
alert(`
login: ${login}
password: ${password}
`);
};
render(){
const { login, password } = this.state;
return(
<div>
<form onSubmit={this.handleSubmit}>
<Fields
text="Введите логин"
type="text"
name="login"
value={login}
onChange={this.handleChange}
/>
<Fields
text="Введите пароль"
type="password"
value={password}
name="password"
onChange={this.handleChange}
/>
<MuiThemeProvider>
<RaiseButtin
label="Войти"
fullWidth={true}
style={style.button}
>
<input
type="submit"
style={style.exampleImageInput}
/>
</RaiseButtin>
</MuiThemeProvider>
</form>
</div>
);
}
}
this.items.forEach((item) => {
this.teams.forEach((team) => {
if (item.team_id === team.id) {
if (team.items) {
team.items.push(item);
} else {
team.items = [item];
}
}
});
});
this.teams.forEach(team => {
team.items = [];
});
import React, { Component } from 'react';
class List extends Component {
state = {
elements: [
{
id: 1,
title: 'First',
},
{
id: 2,
title: 'Second',
},
],
};
handleDeleteElement = id => {
this.setState(prevState => ({
elements: prevState.elements.filter(el => el.id != id);
}));
};
render() {
const { elements } = this.state;
return (
<ul>
{elements.map(el => (
<li
key={el.id}
onClick={() => { this.handleDeleteElement(el.id) }}
>
{el.title}
</li>
))}
</ul>
)
}
}
{items.map(item => (
<Item key={item.id} content={item} />
)}
module.exports = {
context: __dirname + "/public/js/",
entry: "./AuthForm",
output: {
filename: "bundle.js",
path: path.resolve(__dirname + "public/src")
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: ['es2015', 'stage-0', 'react']
}
}]
}
]
}
};
npm install -S babel-preset-es2015 babel-preset-react babel-preset-stage-0