I've designed the following class.
export default class DataView extends React.Component {
private message = "---";
private url = ...;
private body = { ... };
private headers = { ... };
constructor(props: any) {
super(props);
this.message = "executing...";
ajax.post(this.url, this.body, this.headers)
.subscribe(
result => {
this.message = "code " + result.status;
console.log(result.status);
},
error => {
this.message = "Problem: " + error.status;
console.log("Problem: " + error.status)
});
}
render() {
return (
<div style={divStyle}>
Message: {this.message}
</div>);
}
}
The expectation was that the original string would be replaced with the initial message (which happens) and then, the result of the call (which doesn't happen). I'm new to React and not sure what's wrong here. This is the approach I'm using in Angular but, of course, things work a bit differently in React.
The call itself is a success and I can see the correct results in the console. It's only the binding between the class variable and the rendered value that's stale. I've been told that the rendering's done automagically and I should not call render() myself.