I am determining the users OS platform and setting state based on it. I have a function which determines the users OS platform and i am trying to setState, But the property inside the state is always returning false.
Here is my Component.
class HowtoDownload extends React.Component {
constructor(props) {
super(props);
this.state = {
windows: false,
chromebook: false,
ipad: false,
mac: false,
}
componentDidMount() {
console.log("How to Download Component Mounted");
this.getUserPlatform();
console.log(this.state.windows);
}
getUserPlatform = () => {
var OSName = "UnknownOS";
if (navigator.appVersion.indexOf("Win") !== -1)
OSName = "Windows";
this.setState({windows: true});
}
}
this.setStatewhich will always execute its callback function after state is set.