I am using Flow with React and I have a class that uses State and Props types like below:
type B = {x:number}
type State = {
a: ?B
};
type Props = {}
class MyClass extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
a: null,
};
}
...
myFunction=()=>{
console.log(this.state.a.x)// Flow error here
}
}
The Flow error is: Cannot get this.state.a.x because property x is missing in undefined. What is the problem with my type definition? Why should I use 'Props' type definition in my constructor(props: Props) {} ?