const result = Object.values(arr.reduce((acc, n) => {
const group = acc[n.id] = acc[n.id] || { id: n.id, offers: [] };
group.offers.push(n);
return acc;
}, {}));
class Parent extends React.Component {
state = {
inputFoo: '',
inputBaz: ''
};
handleChangeInput = (inputName, value) => {
this.setState({
[inputName]: value
})
}
render() {
const { inputFoo, inputBaz } = this.state;
return (
<div>
<Children1
inputFoo={inputFoo}
inputBaz={inputBaz}
onChangeInput={this.handleChangeInput}
/>
<Children2
inputFoo={inputFoo}
inputBaz={inputBaz}
/>
</div>
);
}
}
class Chidlren1 extends React.Component {
handleInputChange = event => {
const {name, value} = event.target
this.props.onChangeInput(name, value);
}
render() {
const { inputFoo, inputBaz } = this.props;
return (
<div>
<input
type="text"
name="inputFoo"
value={inputFoo}
onChange={this.handleChangeInput}
/>
<input
type="text"
name="inputBaz"
value={inputBaz}
onChange={this.handleChangeInput}
/>
</div>
);
}
}
const mapLangTitleByCode = code => ({
const titles = {
1: 'English',
2: 'Russian',
};
return titles[code] || 'unknown code';
});
<div className="profile-data">
<span>Language</span>
<span>{mapLangTitleByCode(data.q_lang)}</span>
</div>
<div className="profile-data">
<span>Sex</span>
<span>{data.q_sex === 1 ? 'Male' : 'Female'}</span>
</div>