fetchData() {
const { searchValue } = this.state;
fetch("http://localhost:8080/api/users/?name="+searchValue)
.then(/* ... */)
.catch(/* ... */);
}
onSearchClick = () => {
this.setState(prevState => ({
searchValue: prevState.searchInputValue,
}), this.fetchData);
};
class Example extends Component {
this.state = {
error: null,
isLoaded: false,
items: [],
searchValue: '',
searchInputValue: '',
};
onSearchChange = (event, searchInputValue) => {
this.setState({ searchInputValue });
};
onSearchClick = () => {
this.setState(prevState => ({
searchValue: prevState.searchInputValue,
}), () => this.props.getData(this.state.searchValue));
};
render() {
const {
items,
error,
isLoaded,
searchValue
} = this.state;
return (
<div>
<div className={styles.input}>
<Input
leftIcon={<Icon name="search" />}
value={this.state.searchInputValue}
width="700px"
placeholder="Введите Фамилию и Имя"
onChange={this.onSearchChange}
/>
{' '}
<Button use="primary" onClick={this.onSearchClick}>Найти</Button>
</div>
</div>
<div>
<SearchHub
error={error}
isLoaded={isLoaded}
items={items}
searchValue={searchValue}
/>
</div>
);
}
}
if (obj.id === parseInt(action.payload.question_id)) {
return { ...obj, answers: [...obj.answers, action.payload] };
}
содержит ли массив одно из искомых занчений объекта
const foo = (array, string) => array.includes(string);
return array.includes(string);
function Slider(obj) {
this.images = obj.images;
this.autoplayInterval = obj.autoplayInterval;
this.defaultSlide = obj.defaultSlide;
this.autoplaySpeed = obj.autoplaySpeed;
this.init();
}
Slider.prototype.init = function () {
var currentSlide = this.defaultSlide || 1;
var sliderContainer = $(".slider-container");
for (var i = 0; i < this.images.length; i++) {
var slideNumber = i + 1;
var divElem = document.createElement("div");
divElem.classList.add("slider-item");
divElem.classList.add("slide-" + slideNumber);
if (slideNumber == this.defaultSlide) {
divElem.classList.add("slide-active");
}
divElem.style.backgroundImage = 'url(' + this.images[i] + ')';
sliderContainer.append(divElem);
}
if (obj.autoplay) {
setInterval(this.changeSlide.bind(this), this.autoplayInterval);
}
}
Slider.prototype.changeSlide = function () {
if (this.currentSlide === this.images.length) {
currentSlide = 1;
} else {
this.currentSlide++;
}
}