I have the below Code: Where I have an interface type for a state. How do i initialize it in constructor method. As It doesn't allow me to initialize to string/ null/ number
interface IState { selectedUser?: IUserMenu}
class AssignUser extends React.Component<IProps, IState>{ constructor(props: IProps) { super(props); this.state = { selectedUser: ' what i have to put here' }}}
Also what does it mean by
this.state ={}
in the constructor function means ?
IUserMenu is an interface, so I cannot initialize to number, '', null,
Only thing I can use Is undefined
this.state = {}call in the constructor sets the initial state for the component. Perhaps just passthis.state = {}if you don't have an initial value forstate.selectedUser-- your interface indicates it is optional.