Fix react context not being assigned during construction

This commit is contained in:
Michael Telatynski 2021-06-30 13:45:43 +01:00
parent 0a5abb09f4
commit 3a80df4222
2 changed files with 7 additions and 5 deletions

View File

@ -121,14 +121,15 @@ interface IState {
@replaceableComponent("views.rooms.EditMessageComposer")
export default class EditMessageComposer extends React.Component<IProps, IState> {
static contextType = MatrixClientContext;
context: React.ContextType<typeof MatrixClientContext>;
context!: React.ContextType<typeof MatrixClientContext>;
private readonly editorRef = createRef<BasicMessageComposer>();
private readonly dispatcherRef: string;
private model: EditorModel = null;
constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
super(props, context);
super(props);
this.context = context; // otherwise React will only set it prior to render due to type def above
this.state = {
saveDisabled: true,

View File

@ -136,7 +136,7 @@ interface IProps {
@replaceableComponent("views.rooms.SendMessageComposer")
export default class SendMessageComposer extends React.Component<IProps> {
static contextType = MatrixClientContext;
context: React.ContextType<typeof MatrixClientContext>;
context!: React.ContextType<typeof MatrixClientContext>;
private readonly prepareToEncrypt?: RateLimitedFunc;
private readonly editorRef = createRef<BasicMessageComposer>();
@ -146,8 +146,9 @@ export default class SendMessageComposer extends React.Component<IProps> {
private sendHistoryManager: SendHistoryManager;
constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
super(props, context);
if (context.isCryptoEnabled() && context.isRoomEncrypted(this.props.room.roomId)) {
super(props);
this.context = context; // otherwise React will only set it prior to render due to type def above
if (this.context.isCryptoEnabled() && this.context.isRoomEncrypted(this.props.room.roomId)) {
this.prepareToEncrypt = new RateLimitedFunc(() => {
this.context.prepareToEncrypt(this.props.room);
}, 60000);