read-more-and-less
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Introduction - "Read More / Read Less React Component"

npm version NPM

This is an updated iteration of react-read-more-less

"Read More And Less" is react component, which lets you to truncate text based on specified character limit and show a link to "show more" or "show less" of the text.

Installation

npm i read-more-and-less

Import component

// Default import
import ReadMoreAndLess from "read-more-and-less";

// or Named import
import { ReadMoreAndLess } from "read-more-and-less";

Basic Usage

function Example() {
  return (
    <ReadMoreAndLess
      text="Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquam expedita placeat cumque ullam fuga possimus sunt soluta voluptatibus blanditiis consequatur! Magni, maiores necessitatibus repudiandae totam facere officia iste ducimus vitae."
      charLimit={30}
    />
  );
}

Props

Description Type Required Default Value
charLimit The character limit where you want your text to be truncated number No 150
readMoreText The text you want to see in the "Read More" clickable link string No Read More
readLessText The text you want to see in the "Read Less" clickable link string No Read Less
stopPropogation If true then event.stopPropagation() is triggered on all Read More / Read Less link click boolean No true
preventDefault If true then event.preventDefault() is triggered on all Read More / Read Less link click boolean No true
text The text you want to be truncated string Yes N/A

Notes on the original component

The original component itself still works, but it is using outdated dependecies and react class component. In this version, I have updated the dependencies and also implemented react function components.

The build process of the original component was also including react and webpack into its bundle. This was causing some extra load on one of the websites I was working on. In this iteration, I've tried to reduce the bundle size by only bundling the component file itself.

Package Sidebar

Install

npm i read-more-and-less

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

10.6 kB

Total Files

7

Last publish

Collaborators

  • anampartho