window._rutarget = [];
window._rutarget.push({ 'event': 'showOffer' });
window._rutarget = [];
const AdService = {
showOffer() {
window._rutarget.push({'event': 'showOffer'});
},
};
export default AdService;
По техническим причинам на стороне бэкенда нету возможности добавить во второй массив значение type.
array2.forEach(el2 => {
el2.type = array1.find(el1 => el1.idSite === el2.idSite);
});
const array1Clone = array1.slice(0);
array2.forEach(el2 => {
const index = array1Clone.findIndex(el1 => el1.idSite === el2.idSite);
if (index > -1) {
el2.type = array1Clone.splice(index,1)[0].type;
}
});
export default connect(mapStateToProps, null, null, { withRef: true })(Component);
this.someRefName.getWrappedInstance();
render() {
const { res } = this.state;
const shouldFlimDisplayShown = !!res;
return (
<div>
<form onSubmit={this.handleSubmit}>
<label htmlFor="title">Enter title</label>
<input id="title" name="title" type="text" />
<button>Send data!</button>
</form>
{shouldFlimDisplayShown && <FilmDisplay filmName={res}/>}
</div>
);
}
import React from 'react';
class FilmDisplay extends React.Component {
constructor() {
super();
this.state = {
filmData: null
};
}
componentDidMount() {
this.fetchMovie();
}
componentDidUpdate(prevProps) {
if (prevProps.filmData !== this.props.filmData) {
this.fetchMovie();
}
}
fetchMovie() {
const { filmName } = this.props;
const URL = "http://www.omdbapi.com/?t=" + filmName + "&apikey=6540f2ec&";
fetch(URL).then(res => res.json()).then(json => {
this.setState({ filmData: json });
});
}
render() {
const { filmData } = this.state;
if (!filmData) return <div>Loading</div>;
return <div>{JSON.stringify(filmData)}</div>;
}
}
export default FilmDisplay;