|
1 | | -import React, { useEffect, useRef, forwardRef } from "react"; |
| 1 | +import React, { useEffect, useRef, forwardRef, MutableRefObject } from "react"; |
2 | 2 |
|
3 | 3 | interface ChatMessageContentAreaProps { |
4 | 4 | children?: React.ReactNode; |
5 | 5 | } |
6 | 6 |
|
7 | | -const ChatMessageContentArea: React.ForwardRefRenderFunction< |
8 | | - HTMLDivElement, |
9 | | - ChatMessageContentAreaProps |
10 | | -> = (props, ref) => { |
11 | | - const internalRef = useRef<HTMLDivElement>(null); |
12 | | - const combinedRef = ref || internalRef; |
| 7 | +const ChatMessageContentArea = forwardRef<HTMLDivElement, ChatMessageContentAreaProps>( |
| 8 | + (props, ref) => { |
| 9 | + const internalRef = useRef<HTMLDivElement>(null); |
| 10 | + const combinedRef = (ref as MutableRefObject<HTMLDivElement>) || internalRef; |
13 | 11 |
|
14 | | - useEffect(() => { |
15 | | - if (combinedRef && combinedRef.current) { |
16 | | - const links = combinedRef.current.querySelectorAll("a"); |
17 | | - links.forEach(link => { |
18 | | - link.setAttribute("target", "_blank"); |
19 | | - link.setAttribute("rel", "noopener noreferrer"); |
20 | | - }); |
21 | | - } |
22 | | - }, [props.children]); |
| 12 | + useEffect(() => { |
| 13 | + if (combinedRef.current) { |
| 14 | + const links = combinedRef.current.querySelectorAll("a"); |
| 15 | + links.forEach(link => { |
| 16 | + link.setAttribute("target", "_blank"); |
| 17 | + link.setAttribute("rel", "noopener noreferrer"); |
| 18 | + }); |
| 19 | + } |
| 20 | + }, [props.children]); |
23 | 21 |
|
24 | | - return ( |
| 22 | + return ( |
25 | 23 | <div |
26 | | - ref={combinedRef} |
27 | | - className="container max-w-3xl relative min-h-screen pb-[240px] pt-16 flex flex-col gap-16" |
| 24 | + ref={combinedRef} |
| 25 | + className="container max-w-3xl relative min-h-screen pb-[240px] pt-16 flex flex-col gap-16" |
28 | 26 | > |
29 | | - {props.children} |
| 27 | + {props.children} |
30 | 28 | </div> |
31 | | - ); |
32 | | -}; |
| 29 | + ); |
| 30 | + } |
| 31 | +); |
33 | 32 |
|
34 | | -export default forwardRef(ChatMessageContentArea); |
| 33 | +export default ChatMessageContentArea; |
0 commit comments