redux typescript how to dispatch actions code example
Example 1: add redux to react typescript
npm install redux react-redux
npm install -D @types/redux @types/react-redux
Example 2: 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>
);
}
}