this.state.obj.push(this.state.input)
, для обновления стейта всегда нужно использовать setState({})
обязательноcreateTaskBoard = () => {
return this.state.obj.map((item) => <TaskBoard taskType = {item} />)
}
render () {
return (
<div className = 'adder'>
// ... ваш код
{ this.createTaskBoard() }
</div>
)
}
const items = [
{ img: "https://pbs.twimg.com/profile_images/3117087049/697e0334a13361c6ab68ce00aefefa4f.jpeg" },
{ img: "http://vkclub.su/_data/gifts/134.jpg" },
{ img: "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTBIqdLHvhxu4LAxudRrH2OoJSctYh9pw3NyziKUwbpp77tsOvu" }
];
class App extends React.Component {
state = {
image: 1,
}
plus = () => {
const img = this.state.image;
this.setState({
image: (img + 1) % 3,
});
}
minus = () => {
const img = this.state.image;
this.setState({
image: (Math.abs(img - 1)) % 3,
});
}
render() {
const {image} = this.state;
return (
<div>
<button onClick={this.minus}>Prev</button>
<button onClick={this.plus}>Next</button>
{this.state.image}
<img src={items[image].img} />
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('root'));