Skip to content

Commit

Permalink
Merge pull request #7304 from zoran995/fix/react-ref
Browse files Browse the repository at this point in the history
Use useRef instead of createRef in functional component
  • Loading branch information
na9da authored Nov 13, 2024
2 parents f102e34 + abe743e commit fc5b52b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### next release (8.7.9)

- Properly initialize react ref in functional components
- [The next improvement]

#### 8.7.8 - 2024-11-01
Expand Down
4 changes: 2 additions & 2 deletions lib/ReactViews/Tools/ItemSearchTool/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { observer } from "mobx-react";
import Mustache from "mustache";
import React, { useState } from "react";
import React, { useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useVirtual } from "react-virtual";
import styled from "styled-components";
Expand Down Expand Up @@ -28,7 +28,7 @@ const SearchResults: React.FC<SearchResultsProps> = (props) => {
currentMapEffect.is === "highlightSingleResult"
? currentMapEffect.result
: undefined;
const parentRef = React.createRef<HTMLDivElement>();
const parentRef = useRef<HTMLDivElement>(null);
const list = useVirtual({
size: results.length,
parentRef,
Expand Down
4 changes: 2 additions & 2 deletions lib/ReactViews/Tools/PedestrianMode/MouseTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createRef, useEffect } from "react";
import React, { useEffect, useRef } from "react";
import styled from "styled-components";
import Cartesian2 from "terriajs-cesium/Source/Core/Cartesian2";
import Scene from "terriajs-cesium/Source/Scene/Scene";
Expand All @@ -11,7 +11,7 @@ type MouseTooltipProps = {

const MouseTooltip: React.FC<MouseTooltipProps> = (props) => {
const { scene, text } = props;
const tooltipText = createRef<typeof TooltipText>();
const tooltipText = useRef<typeof TooltipText>(null);

useEffect(function tooltipFollowMouse() {
const setTooltipPosition = (position: { x: number; y: number }) => {
Expand Down

0 comments on commit fc5b52b

Please sign in to comment.