redux connect typescript code example
Example 1: add redux to react typescript
npm install redux react-redux
npm install -D @types/redux @types/react-redux
Example 2: react redux typescript
Example 3: 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}
>
Play
</button>
</div>
);
}
}
Example 4: react redux typescript