I am working on a React component that receives a long string and a numerical variable as props. The component’s objective is to display a trimmed version of the string, based on the specified number variable. Additionally, it should include "show more" and "show less" buttons.
Despite attempting various approaches, none have proven successful. The original single-line string becomes multi-lined when placed within a div with defined width and height. My primary challenge arises when using the "useRef" hook to access textRef.current.innerHTML, which returns the original string without ‘n’ characters.
Do you have any suggestions on how to address this issue?
2
Answers
Following @AdamBasha answer and this video, here's the solution. Note that the main css attribute, WebkitLineClamp, is being changed dynamically in the react code:
and
I don’t know how you are trying to achieve it, but this is a working example of a Read more and Read less that I have developed.
I hope it helps