Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get x amount of letters from some text in React.js

Here is my component, I want to do this: if the text has 50 letters show them and if it has more than 50 show the text and …

const Post: React.FC = ({
  text
}) => {
  return ( <p> {text} </p> );
};

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can achieve that using slice(starting value, ending value)

<p> {text ? .length >= 50 ? text ? .slice(0, 50) + "..." : text} </p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading