JSFiddle - React, Tailwind, and code Playground
HTML
<a href='test'>
<script>
truncate("truncate this text");
</script>
</a>
JavaScript
function truncate(string){
if (string.length > 5)
return string.substring(0,5)+'...';
else
return string;
};