typescript types for state

interface IProps {
}

interface IState {
  playOrPause?: string;
}

class Player extends React.Component<IProps, IState> {
  // ------------------------------------------^
  constructor(props: IProps) {
    super(props);

    this.state = {
      playOrPause: 'Play'
    };
  }

  render() {
    return(
      <div>
        <button
          ref={playPause => this.playPause = playPause}
          title={this.state.playOrPause} // in this line I get an error
        >
          Play
        </button>
      </div>
    );
  }
}

4
4
Caitlin 95 points

                                    interface IProps {
}

interface IState {
  playOrPause?: string;
}

class Player extends React.Component&lt;IProps, IState&gt; {
  // ------------------------------------------^
  constructor(props: IProps) {
    super(props);

    this.state = {
      playOrPause: 'Play'
    };
  }

  render() {
    return(
      &lt;div&gt;
        &lt;button
          ref={playPause =&gt; this.playPause = playPause}
          title={this.state.playOrPause} // in this line I get an error
        &gt;
          Play
        &lt;/button&gt;
      &lt;/div&gt;
    );
  }
}

4 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
typescript types for state new state typescript typeScript type for state funtion typestate typescript state react native typescript handle state in typescript react set state i typescript typescript give state a type set state typescript state in class component in react using typescript how to type state react typescript state typescript typescriptstate in react how to set a type for a use state in typescript react state with ts react state and props typescript types of states typescript set state in typescript call state on react typescript statevalue react typescript typescript in react state use state with typescript react typescript with state ts set state type typescript type state typescript state type of value set state property type typescript react typescript in state update state react typescript state type typescript typescript state component what type is react state typescript typescript state react type typescript this.state class component state in react typescript state in typescript react typescript state type typescript state code type react this.state typescript typescript this.state react react native typescript this.state typescript define state react state in class components typescript set state type typescript react typescript type set state functions react states with typescript set state type typescript react typescript state for component typescript react state management across components react class component typescript state typescript define your state state numbers typescript react type state react typescript how to give types in use state in tsx typescript state typescript type for react state react set state to type typescritp how to set state in typescript react state in component typescript react typescript clase this.state types react typescript state management typescript define type of state react state typescript type give type to react state typescript typescript react with state typescript set state types state typescript state in typescript react state components typescript react typescript set state typescript state reactjs function typescript state reactjs react stateful component typescript state of typescript React set State Typescript use state react typescript set state react typescript react typescript state item of type how type property in typescript state react react typescript functional component state declare a type with optional state typescript react typescript local state typescript react class props define state react typescript typescript tsx reducer enforce new state addition object interface reactjs typescript class state react native typscrtipt component with props and state typescript state type object create new class in react with type script define type for a typescript react component class typescript usestate react typescript state only gets updated by last expression this.state react typescript state in react functional component typescript props and state in a react component in typescript how get data from state in react typescript get state from props typescript assign type to redux object typescript react state type typescript usestate redux connect typescript type of redux store react compenent typescript thunk connect react redux typescript usestate react typescript typescript and setState typescript redux middleware typescrip store redux typeof state typescript this.state in typescript react dispatch type typescript dispatch method redux typescript pure component react.usestate typescript react component typed react typescript object what type is store typescript react native typescript state function component react native typescript state return type redux store in typescript redux typescript getstate React.Component yupescript redux typescript how to pass props in typescript react without setstate class component typescript dispatch function typescript copy existing state react typecscript reducer typescript state of an object react typescript redux anyreducer typescript redux typescript how to dispatch actions redux typescript dispatch state tsx react type redux type typescript redux action redux dispatch type how to type state in typescript how to type state typescript redux thunk dispatch typescript react typescript state type redux actions types typescript typescript thunk types typescript redux combinereducers redux actions ts typescript reducer get state type redux redux types react typescript state object react state with typescript how do i type a redux thunk typescript this.state typescript typescript react pure component typescript for state react usestate typescript usage of use selector inside react class typescript typescript react component class typescript this.state.property react typescript this.state react component props typescript assign specific string values react typescript usestate types how to use ! in typescript state react class componenet with type script typescript react as property how to add state to react ts Typescript react object payload object state react typescript render a state in ts react ts react class component state react typescript constructor react typescript react typescrit class react ts classes state typescript class component react state defining state in typescript how to define state in tsx react typescript state type interface typescript class component set state react typescript class component call with props react state typescript store&lt;stateInterface&gt; typescript how to use this.state in typescript react ts component example how to set a state in react using typescript react components in typescript react typescript components reactjs typescript constructor props reactjs typescript class component react component simple state typescript react typescript constructor typescript react call class component react ts class component this.props? typescript this.props? typscript componet type react react class react.componentclass typescript constructor props typescript React ts interface state typescript for class component + react how to define state in typescript react state in react with typescript react typescript class based component state typescript react class based component react typescript component state component willappea typescript react typescript component react.component props state typescript react class component with typescr should I use component state with typescript react typescript do I need state properties class components typescript react with typescript class component react extends component typescript define react component in typescript turneraryy react typescript state react typscript react typescript component example react component in typescript typescript react component example ts react arguments how to pass state to component react typescript interface how to pass state to component react typescript how to pass props in typescript passing state with typescript props passing state with typescript propa react class and ts typescript react state ts react component react typescript state interface react class with typescript react flass componetn typesctipt state typescirpt react typescript react component props typscript value for react component typescript class props how to pass props to components in react typescript typescript pass props to component passing props in typescript typescript react native passing props react class component tsx simple typescript react component typescript type this.state typescript props typescript function component react react native typescript components without render react typescript props functional component react typescript set a type typescript and functional components react importing typescript component in javascript react example typescript component how to use react class component in typescript props typescript react functional component typescript props react tsx functional component how to pass a prop in typescript typescript props from component use state in react class component typescript what is @prop in typescript how to create a component in typescript how to pass props to a class in typescript class react typescript react component typescript writing react components in typescript pass props in a typescript react component create a react component in typescript function component react typescript react typescript state function function component typescript react props tsx how props work in react typescript using props react tsx function component props state react typescript tsx react component example react props typescript react components tsx typescript react props typescript react props with being passed react typescript state passing props typescript react component with props typescript typescript in react but functional components FunctionComponent typescript react class component typescript react native typescript functional component class component in react typescript react tpye javascript component with TypeScript class component typescript react components typescript react.function component typescript react typescript prop typescript react component typescript react class state react class component state typescript functional React Native components with TypeScript functional React components with TypeScript import component react typescript react function component typescript props typescript class component typescript react export const element componentdidmount typescript set function as state react ts class based component react props typescript props typescript react ts react component type for function and class what is a general type for a react component typescript typescript react class component react typescript props import react component any typescript typescript react components typescript component example react component template typescript typescript component state class component react typescript react props class tsx example react typescript functional component function componenets with typescript react functional component props typescript typescript props class component typing react components class component typescript props typescript create component state typescript react react typescript class component state not working react typescript class component state react typescript class component react typescript class component props typescript component state in react typescript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source