Revert "chore: replace createRef with useRef in most of the places (#21536)"

This reverts commit 908c0462d5.
This commit is contained in:
Pavel 2023-03-09 16:46:31 -08:00
parent 908c0462d5
commit a619ea4d68
6 changed files with 19 additions and 18 deletions

View File

@ -30,7 +30,7 @@ export const CallLogView: React.FC<CallLogProps> = ({
language,
log,
}) => {
const messagesEndRef = React.useRef<HTMLDivElement>(null);
const messagesEndRef = React.createRef<HTMLDivElement>();
const [expandOverrides, setExpandOverrides] = React.useState<Map<string, boolean>>(new Map());
React.useLayoutEffect(() => {
if (log.find(callLog => callLog.reveal))

View File

@ -78,7 +78,7 @@ export const Recorder: React.FC<RecorderProps> = ({
setFileId(value);
};
const messagesEndRef = React.useRef<HTMLDivElement>(null);
const messagesEndRef = React.createRef<HTMLDivElement>();
React.useLayoutEffect(() => {
messagesEndRef.current?.scrollIntoView({ block: 'center', inline: 'nearest' });
}, [messagesEndRef]);

View File

@ -70,7 +70,7 @@ export const SourceTab: React.FunctionComponent<{
const targetLine = typeof stackInfo === 'string' ? 0 : stackInfo.frames[selectedFrame]?.line || 0;
const targetLineRef = React.useRef<HTMLDivElement>(null);
const targetLineRef = React.createRef<HTMLDivElement>();
React.useLayoutEffect(() => {
if (needReveal && targetLineRef.current) {
targetLineRef.current.scrollIntoView({ block: 'center', inline: 'nearest' });

View File

@ -49,9 +49,9 @@ export const CodeMirrorWrapper: React.FC<SourceProps> = ({
wrapLines,
onChange,
}) => {
const codemirrorElement = React.useRef<HTMLDivElement>(null);
const codemirrorElement = React.createRef<HTMLDivElement>();
const [modulePromise] = React.useState<Promise<CodeMirror>>(import('./codeMirrorModule').then(m => m.default));
const [codemirror] = React.useState<{ value?: CodeMirror.Editor }>({});
const [codemirror, setCodemirror] = React.useState<CodeMirror.Editor>();
React.useEffect(() => {
(async () => {
@ -70,17 +70,18 @@ export const CodeMirrorWrapper: React.FC<SourceProps> = ({
if (language === 'csharp')
mode = 'text/x-csharp';
if (codemirror.value
&& mode === codemirror.value.getOption('mode')
&& readOnly === codemirror.value.getOption('readOnly')
&& lineNumbers === codemirror.value.getOption('lineNumbers')
&& wrapLines === codemirror.value.getOption('lineWrapping')) {
updateEditor(codemirror.value, text, highlight, revealLine, focusOnChange);
if (codemirror
&& mode === codemirror.getOption('mode')
&& readOnly === codemirror.getOption('readOnly')
&& lineNumbers === codemirror.getOption('lineNumbers')
&& wrapLines === codemirror.getOption('lineWrapping')) {
updateEditor(codemirror, text, highlight, revealLine, focusOnChange);
return;
}
// Either configuration is different or we don't have a codemirror yet.
codemirror.value?.getWrapperElement().remove();
if (codemirror)
codemirror.getWrapperElement().remove();
const cm = CodeMirror(element, {
value: '',
@ -89,7 +90,7 @@ export const CodeMirrorWrapper: React.FC<SourceProps> = ({
lineNumbers,
lineWrapping: wrapLines,
});
codemirror.value = cm;
setCodemirror(cm);
if (onChange)
cm.on('change', () => onChange(cm.getValue()));
updateEditor(cm, text, highlight, revealLine, focusOnChange);

View File

@ -52,7 +52,7 @@ export function ListView<T>({
noItemsMessage,
dataTestId,
}: ListViewProps<T>) {
const itemListRef = React.useRef<HTMLDivElement>(null);
const itemListRef = React.createRef<HTMLDivElement>();
const [highlightedItem, setHighlightedItem] = React.useState<any>();
React.useEffect(() => {

View File

@ -30,9 +30,9 @@ export type XtermDataSource = {
export const XtermWrapper: React.FC<{ source: XtermDataSource }> = ({
source
}) => {
const xtermElement = React.useRef<HTMLDivElement>(null);
const xtermElement = React.createRef<HTMLDivElement>();
const [modulePromise] = React.useState<Promise<XtermModule>>(import('./xtermModule').then(m => m.default));
const [terminal] = React.useState<{ value?: Terminal }>({});
const [terminal, setTerminal] = React.useState<Terminal>();
React.useEffect(() => {
(async () => {
// Always load the module first.
@ -41,7 +41,7 @@ export const XtermWrapper: React.FC<{ source: XtermDataSource }> = ({
if (!element)
return;
if (terminal.value)
if (terminal)
return;
const newTerminal = new Terminal({
@ -65,7 +65,7 @@ export const XtermWrapper: React.FC<{ source: XtermDataSource }> = ({
};
newTerminal.open(element);
fitAddon.fit();
terminal.value = newTerminal;
setTerminal(newTerminal);
const resizeObserver = new ResizeObserver(() => {
source.resize(newTerminal.cols, newTerminal.rows);
fitAddon.fit();