import React, { Component } from 'react'
import axios from 'axios'
import classes from './DataProvider.css'
import ReactHtmlParser from 'react-html-parser'
class DataProvider extends Component {
constructor(props){
super(props)
this.state = {
history: [],
isShowHistory: false,
activeHistory: null,
}
// this.showHistory = this.showHistory.bind(this)
}
componentDidMount(){
axios.get('https://blabla.ru/restapi/api/lead/', {method: 'HEAD', mode: 'no-cors'})
.then(response => {
let history = response.data
this.setState({
history
})
console.log(history);
})
}
showHistory = (id) => {
this.setState({
isShowHistory: !this.state.isShowHistory
})
}
render(){
return(
<div className="row d-flex justify-content-center">
{this.state.history.map((item) => {
const showHandleHis = () => this.showHistory(item.id);
return (
<div className={classes.DataProvider + " col-sm-6 my-2"} key={item.id}>
<img src={item.image_lead} />
<h3>{item.name}</h3>
{ReactHtmlParser(this.state.isShowHistory ? item.history : null)}
<button className={classes.Button}
onClick={showHandleHis}>
{!this.state.isShowHistory ? 'Показать историю' : 'Скрыть историю'}
</button>
</div>
)
})}
</div>
)
}
}
export default DataProvider
Не ребит мб что то добавить в showHistory? что не пойму и как...
this.setState({ history })
сделатьthis.setState({ history: history })
? – Dmitry Kozlov 10 ноя '18 в 18:16