Browse Source

add type and cleanupFn

yohei0125 4 years ago
parent
commit
514942ae91
1 changed files with 5 additions and 3 deletions
  1. 5 3
      packages/app/src/components/SearchPage/SearchResultContent.tsx

+ 5 - 3
packages/app/src/components/SearchPage/SearchResultContent.tsx

@@ -56,7 +56,7 @@ type Props ={
 const SearchResultContent: FC<Props> = (props: Props) => {
 const SearchResultContent: FC<Props> = (props: Props) => {
 
 
   // ***************************  Auto Scroll  ***************************
   // ***************************  Auto Scroll  ***************************
-  const scrollTo = (scrollElement) => {
+  const scrollTo = (scrollElement:HTMLElement) => {
     const highlightedKeyword = scrollElement.querySelector('.highlighted-keyword') as HTMLElement;
     const highlightedKeyword = scrollElement.querySelector('.highlighted-keyword') as HTMLElement;
     if (highlightedKeyword != null) {
     if (highlightedKeyword != null) {
       smoothScrollIntoView(highlightedKeyword, SCROLL_OFFSET_TOP, scrollElement);
       smoothScrollIntoView(highlightedKeyword, SCROLL_OFFSET_TOP, scrollElement);
@@ -67,7 +67,7 @@ const SearchResultContent: FC<Props> = (props: Props) => {
     const scrollElement = document.querySelector('.search-result-page-content') as HTMLElement;
     const scrollElement = document.querySelector('.search-result-page-content') as HTMLElement;
     if (scrollElement == null) return;
     if (scrollElement == null) return;
     const observerCallback = (mutationRecords) => {
     const observerCallback = (mutationRecords) => {
-      mutationRecords.forEach((record:any) => {
+      mutationRecords.forEach((record) => {
         const targetId = record.target.id;
         const targetId = record.target.id;
         if (targetId !== 'wiki') return;
         if (targetId !== 'wiki') return;
         scrollTo(scrollElement);
         scrollTo(scrollElement);
@@ -75,7 +75,9 @@ const SearchResultContent: FC<Props> = (props: Props) => {
     };
     };
     const observer = new MutationObserver(observerCallback);
     const observer = new MutationObserver(observerCallback);
     observer.observe(scrollElement, MUTATION_OBSERVER_CONFIG);
     observer.observe(scrollElement, MUTATION_OBSERVER_CONFIG);
-    return;
+    return () => {
+      observer.disconnect();
+    };
   });
   });
   // ***************************  end  ***************************
   // ***************************  end  ***************************