2024-02-19 18:59:45 +08:00
|
|
|
import React, { useEffect, useRef } from 'react';
|
2024-06-11 03:31:30 +08:00
|
|
|
import { GenericContentItemProps } from './types';
|
2024-02-19 18:59:45 +08:00
|
|
|
|
2024-06-11 03:31:30 +08:00
|
|
|
const GenericContentItem: React.FC<GenericContentItemProps> = (props) => {
|
2024-02-19 18:59:45 +08:00
|
|
|
const {
|
|
|
|
renderFunction,
|
2024-09-28 01:48:05 +08:00
|
|
|
width,
|
2024-02-19 18:59:45 +08:00
|
|
|
} = props;
|
|
|
|
const elementRef = useRef(null);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (elementRef.current && renderFunction) {
|
|
|
|
renderFunction(elementRef.current);
|
|
|
|
}
|
|
|
|
}, [elementRef]);
|
|
|
|
|
2024-09-28 01:48:05 +08:00
|
|
|
const style: React.CSSProperties = {
|
|
|
|
height: '100%',
|
|
|
|
overflow: 'hidden',
|
|
|
|
};
|
|
|
|
if (width) {
|
|
|
|
style.width = width;
|
|
|
|
}
|
2024-02-19 18:59:45 +08:00
|
|
|
return (
|
|
|
|
<div
|
2024-09-28 01:48:05 +08:00
|
|
|
style={style}
|
2024-02-19 18:59:45 +08:00
|
|
|
ref={elementRef}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-06-11 03:31:30 +08:00
|
|
|
export default GenericContentItem;
|