Want to declare a property in constructor with typescript react? Yeah, there’s a problem there that I haven’t noticed, it should be:
1 2 3 4 5 6 7 8 9 10 11 12 13 | class Main extends React.Component<MainProps, MainState> { constructor(props) { super(props); this.state = { todos: [], editorState: EditorState.createEmpty() }; this.onChange = (editorState) => this.setState({ editorState: editorState } as MainState); } onChange: (state: MainState) => void; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.