I think that the solution exactly that you asked. Hide the button if 3 row visible of less. If small screen it's adaptive. woking example
Wrapped.js
const Description = () => {
const [isShowMore, setIsShowMore] = useState(true);
const [hasMore, setHasMore] = useState(false);
const [bodyWidth, setBodyWidth] = useState(0);
const ref = useRef(null);
const toggleReadMore = () => setIsShowMore(show => !show);
useEffect(() => {
const resize = () => {
const getWidth = document.body.clientWidth;
setBodyWidth(getWidth);
};
window.addEventListener('resize', resize);
const text = ref.current;
const hiddenText = text.scrollHeight;
const visibleText = +getComputedStyle(text)
.getPropertyValue('height')
.replace('px', '');
if (visibleText < hiddenText) {
setHasMore(true);
} else {
setHasMore(false);
}
return () => {
window.removeEventListener('resize', resize);
};
}, [bodyWidth]);
useEffect(() => {
const getWidth = document.body.clientWidth;
setBodyWidth(getWidth);
}, []);
return (
<MainContainer>
<TitleText>Description</TitleText>
<DescriptionText showMore={isShowMore} ref={ref}>
{text}
</DescriptionText>
{hasMore ? (
<ShowMoreText onClick={toggleReadMore}>
{isShowMore ? 'Show more...' : 'Show less'}
</ShowMoreText>
) : null}
</MainContainer>
);
};
export default Description;