Typescript and React setting initial state with empty typed array

前端 未结 3 1666
醉梦人生
醉梦人生 2021-02-12 16:00

Say I have the following snippet:

interface State {
  alarms: Alarm[];
}
export default class Alarms extends React.Component<{}, State> {
  state = {
    a         


        
3条回答
  •  感动是毒
    2021-02-12 16:12

    Declaration:

    alarms: Array

    Initialization in state :

    this.setState({
    var1:'',
    var2:''
    });
    

    I prefer the above declaration

提交回复
热议问题