Skip to content

Commit

Permalink
fix(shell, logging): replace createRef with useRef (#5943)
Browse files Browse the repository at this point in the history
  • Loading branch information
gribnoysup authored Jun 18, 2024
1 parent d9383fe commit 866e1a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
8 changes: 4 additions & 4 deletions packages/compass-logging/src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useRef } from 'react';
import type {
LoggerAndTelemetry,
LoggingAndTelemetryPreferences,
Expand Down Expand Up @@ -56,9 +56,9 @@ export function useLoggerAndTelemetry(component: string): LoggerAndTelemetry {
if (!context) {
throw new Error('LoggerAndTelemetry service is missing from React context');
}
const loggerRef = React.createRef<LoggerAndTelemetry>();
const loggerRef = useRef<LoggerAndTelemetry>();
if (!loggerRef.current) {
(loggerRef as any).current = context.createLogger(
loggerRef.current = context.createLogger(
component,
context.preferences ?? {
getPreferences() {
Expand All @@ -67,7 +67,7 @@ export function useLoggerAndTelemetry(component: string): LoggerAndTelemetry {
}
);
}
return loggerRef.current!;
return loggerRef.current;
}

export function useTrackOnChange(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { connect } from 'react-redux';
import React, {
useCallback,
useEffect,
useRef,
createRef,
useState,
} from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { useTabState } from '@mongodb-js/compass-workspaces/provider';
import {
Banner,
Expand Down Expand Up @@ -67,7 +61,7 @@ const CompassShell: React.FC<CompassShellProps> = ({
emitShellPluginOpened,
}) => {
const enableShell = usePreference('enableShell');
const shellRef = createRef<ShellType>();
const shellRef = useRef<ShellType>(null);
const emitShellPluginOpenedRef = useRef(emitShellPluginOpened);
emitShellPluginOpenedRef.current =
emitShellPluginOpened ??
Expand Down Expand Up @@ -112,8 +106,7 @@ const CompassShell: React.FC<CompassShellProps> = ({

const focusEditor = useCallback(() => {
if (shellRef.current && window.getSelection()?.type !== 'Range') {
(shellRef.current as any) /* private ... */
.focusEditor();
shellRef.current['focusEditor']();
}
}, [shellRef]);

Expand Down

0 comments on commit 866e1a3

Please sign in to comment.