1.0.1 • Published 11 months ago

read-more-and-less v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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

DescriptionTypeRequiredDefault Value
charLimitThe character limit where you want your text to be truncatednumberNo150
readMoreTextThe text you want to see in the "Read More" clickable linkstringNoRead More
readLessTextThe text you want to see in the "Read Less" clickable linkstringNoRead Less
stopPropogationIf true then event.stopPropagation() is triggered on all Read More / Read Less link clickbooleanNotrue
preventDefaultIf true then event.preventDefault() is triggered on all Read More / Read Less link clickbooleanNotrue
textThe text you want to be truncatedstringYesN/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.

1.0.1

11 months ago

1.0.0

11 months ago

0.0.1

11 months ago