constructor react typescript code example
Example 1: react tsx component example
import React from 'react';
interface Props {
}
const App: React.FC<Props> = (props) => {
return (
<div><div/>
);
};
export default App;
Example 2: state in react typescript
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>
);
}
}