Can anyone explain what is happening in this code please?
I have a Reactjs module which I have used a ReactDataGrid component in it. The important part of the code is like these:
export default class IssueTable extends Component {
state = {
issues: [],
postHtml: {},
isFullScreenMode: false,
loading: true,
columns: []
}
componentDidMount = () => {
this.props.getIssues(filter).then(response => {
...
//******** PLACE 1 THAT I THINK IT SHOULD WORK, BUT NOT! **********
//this.createIssueTableServiceObject()
...
this.refreshTable()
})
}
createIssueTableServiceObject() {
issuleTableService = {
getColumns: () => this.columns,
updateTableRow: this.handleRowsUpdated,
getPostHtml: issueId => this.state.postHtml[issueId],
getOriginalRow: rowIndex => this.originalIssues[rowIndex],
getRenderedRow: rowIndex => this.state.issues[rowIndex]
};
}
refreshTable = () => {
//******** PLACE 2 THAT IT WORKS **********
this.createIssueTableServiceObject()
this.setState({
...
})
}
columns = [{
....
formatter: (props) => {
return (<IssueCell
{...props}
issuleTableService= {issuleTableService}
/>)
}
}]
}
export let issuleTableService
Because there is no configuration to send data to the subcomponent of the React Data Grid library (Version ^7.0.0-canary.16), I need to have an export object import it in modules I need like editor which is a property on the column.
The problem is that for the first rows which table is rendering, all things are normal. But when I want to do some changes on the rows, the state of the component in the exported object is like the previous state (before editing):
getPostHtml: issueId => this.state.postHtml[issueId], //**** this.state has not updated values
So I need to move the export object creation to the place 2 in code to execute it and refresh it in every table refreshing.
My question is that what is happening for "this" in the export object? Does it keep a copy of the "this"?