I've done a conditional rendering statement within react.The condition that I'm checking is based on the server response. If the condition is met then I've to render some UI components otherwise a different UI. So the problem is what ever I'm getting from server, only the else portion is working.I've double checked the response
also.
updated code
export default class ViewStatus extends Component {
constructor(props) {
super(props);
this.initialState = {
progressData: [],
};
this.state = this.initialState;
}
componentWillMount(){
fetch('http://192.168.1.2:3000/api/progress',{
method:'POST',
headers:{
'Accept': 'application/json',
'Content-Type':'application/json'
},
body:JSON.stringify({
work_type:this.props.work_type
})
})
.then(response => response.json())
.then((responseData) => {
this.setState({
progressData:responseData[0]
});
});
}
render() {
const isResponseData = this.state.progressData == '1' ? this.renderDone() : this.renderInProgress()
console.log(this.state.progressData);
return(
<View>
{isResponseData}
</View>
);
}
renderInProgress(){
return(
<View>
<Text>In Progress</Text>
<Text>Worker will approach you within 24 hrs.</Text>
</View>
);
}
renderDone(){
return(
<View>
<Text>Successfull</Text>
<Text>Are you satisfied with the work .If yes please mark done.</Text>
</View>
);
}