Skip to content

Commit 866e1a3

Browse files
authored
fix(shell, logging): replace createRef with useRef (#5943)
1 parent d9383fe commit 866e1a3

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

packages/compass-logging/src/provider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useRef } from 'react';
22
import type {
33
LoggerAndTelemetry,
44
LoggingAndTelemetryPreferences,
@@ -56,9 +56,9 @@ export function useLoggerAndTelemetry(component: string): LoggerAndTelemetry {
5656
if (!context) {
5757
throw new Error('LoggerAndTelemetry service is missing from React context');
5858
}
59-
const loggerRef = React.createRef<LoggerAndTelemetry>();
59+
const loggerRef = useRef<LoggerAndTelemetry>();
6060
if (!loggerRef.current) {
61-
(loggerRef as any).current = context.createLogger(
61+
loggerRef.current = context.createLogger(
6262
component,
6363
context.preferences ?? {
6464
getPreferences() {
@@ -67,7 +67,7 @@ export function useLoggerAndTelemetry(component: string): LoggerAndTelemetry {
6767
}
6868
);
6969
}
70-
return loggerRef.current!;
70+
return loggerRef.current;
7171
}
7272

7373
export function useTrackOnChange(

packages/compass-shell/src/components/compass-shell/tab-compass-shell.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { connect } from 'react-redux';
2-
import React, {
3-
useCallback,
4-
useEffect,
5-
useRef,
6-
createRef,
7-
useState,
8-
} from 'react';
2+
import React, { useCallback, useEffect, useRef, useState } from 'react';
93
import { useTabState } from '@mongodb-js/compass-workspaces/provider';
104
import {
115
Banner,
@@ -67,7 +61,7 @@ const CompassShell: React.FC<CompassShellProps> = ({
6761
emitShellPluginOpened,
6862
}) => {
6963
const enableShell = usePreference('enableShell');
70-
const shellRef = createRef<ShellType>();
64+
const shellRef = useRef<ShellType>(null);
7165
const emitShellPluginOpenedRef = useRef(emitShellPluginOpened);
7266
emitShellPluginOpenedRef.current =
7367
emitShellPluginOpened ??
@@ -112,8 +106,7 @@ const CompassShell: React.FC<CompassShellProps> = ({
112106

113107
const focusEditor = useCallback(() => {
114108
if (shellRef.current && window.getSelection()?.type !== 'Range') {
115-
(shellRef.current as any) /* private ... */
116-
.focusEditor();
109+
shellRef.current['focusEditor']();
117110
}
118111
}, [shellRef]);
119112

0 commit comments

Comments
 (0)