onChange = ({ target: { value, dataset: { objName, key } } }) => {
this.setState(({ [objName]: obj }) => ({
[objName]: {
...obj,
[key]: value,
},
}));
}
<input data-obj-name="fr" data-key="name" value={this.state.fr.name} onChange={this.onChange} />
<input data-obj-name="en" data-key="title" value={this.state.en.title} onChange={this.onChange} />
Browser engineers recommend pages contain fewer than ~1,500 DOM nodes. The sweet spot is a tree depth < 32 elements and fewer than 60 children/parent element. A large DOM can increase memory usage, cause longer style calculations, and produce costly layout reflows. Learn more.
class Parent extends React.Component {
state = {
count: 0,
}
onClick = () => {
this.setState(({ count }) => ({
count: count + 1,
}));
}
render() {
return (
<div>
<button onClick={this.onClick}>Добавить компонент</button>
{Array.from({ length: this.state.count }, () => <Input />)}
</div>
);
}
}
class Parent extends React.Component {
state = {
someStateKey: false,
};
someHandler = () => {
this.setState({ someStateKey: true });
};
render() {
return (
<Wrapper>
<ChildA someHandler={this.someHandler} />
<ChildB stateKey={this.state.someStateKey} />
</Wrapper>
);
}
}
<div class="container">
<section class="news">
<div class="news__item">Новость</div>
<div class="news__item">Новость</div>
<div class="news__item">Новость</div>
<div class="news__item">Новость</div>
<div class="news__item">Новость</div>
</section>
<aside class="sideBar">Боковое меню</aside>
</div>
.container{
display: flex;
max-width: 1200px;
background: #eee;
margin: 0 auto;
}
.news{
display: flex;
flex-wrap: wrap;
flex-grow: 1;
background: lightgreen;
}
.news__item{
flex-basis: 200px;
flex-grow: 1;
height: 300px;
margin: 10px;
background: lightblue;
}
.sideBar{
flex-grow: 1;
max-width: 400px;
}
for (size in burger) { // size будет 'smallburger' и 'bigburger'
for (prop in burger[size]) { // внутри каждого: 'name', 'cost' и 'ccal'
console.log(size, prop, burger[size][prop]);
}
}
$('.click-to-remove-class').click() {
$($(this).data('selector-where-to-remove-class')).removeClass('d-none');
}
<a href='#' id='novosib-button' class='click-to-remove-class' data-selector-where-to-remove-class = '#novosib-city'>
Click here
</a>
<div id='novosib-city' class='d-none'>...</div>