Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

onclick readmore and readless react js

import React, { useState } from 'react';

const ReadMore = ({text}) => {
  const [isReadMore, setIsReadMore] = useState(true);
  const toggleReadMore = () => {setIsReadMore(!isReadMore)};

  return (
    <p className='testimonials__quote__text'>
      {isReadMore ? text.slice(0, 150): text }
      // condition that will render 'read more' only if the text.length is greated than 150 chars
      {text.length > 150 &&
        <span onClick={toggleReadMore}>
          {isReadMore ? '...read more' : ' ...show less'}
        </span>
      }
    </p>
  )
}

export default ReadMore;
Comment

onclick readmore and readless react js

import React, { useState } from 'react';

const ReadMore = ({text}) => {
  const [isReadMore, setIsReadMore] = useState(true);
  const toggleReadMore = () => {setIsReadMore(!isReadMore)};

  return (
    <p className='testimonials__quote__text'>
      {isReadMore ? text.slice(0, 150): text }
      // condition that will render 'read more' only if the text.length is greated than 150 chars
      {text.length > 150 &&
        <span onClick={toggleReadMore}>
          {isReadMore ? '...read more' : ' ...show less'}
        </span>
      }
    </p>
  )
}

export default ReadMore;
Comment

onclick readmore and readless react js

import React, { useState } from 'react';

const ReadMore = ({text}) => {
  const [isReadMore, setIsReadMore] = useState(true);
  const toggleReadMore = () => {setIsReadMore(!isReadMore)};

  return (
    <p className='testimonials__quote__text'>
      {isReadMore ? text.slice(0, 150): text }
      // condition that will render 'read more' only if the text.length is greated than 150 chars
      {text.length > 150 &&
        <span onClick={toggleReadMore}>
          {isReadMore ? '...read more' : ' ...show less'}
        </span>
      }
    </p>
  )
}

export default ReadMore;
Comment

PREVIOUS NEXT
Code Example
Javascript :: check for overlapping time javascript 
Javascript :: useState intro 
Javascript :: use function in mongodb query example 
Javascript :: Validation Script Rule 
Javascript :: winston transport file another directory 
Javascript :: How to Loop Through an Array with a for…of Loop in JavaScript 
Javascript :: JSON of first block in cryptocurrency blockchain 
Javascript :: Backbone Model Validation And Inheritance 
Javascript :: Backbone With Express 
Javascript :: Check If Backbone Model Has Property 
Javascript :: How do I target and change the style of a different element when I click a button in react 
Javascript :: adding javascript object within array 
Javascript :: react custum toogle 
Javascript :: event 
Javascript :: how to check leap year in javascript 
Javascript :: array max in javascript 
Javascript :: mounting in react 
Javascript :: react native new project 
Javascript :: jsx attributes 
Javascript :: array.map method 
Javascript :: animate js 
Javascript :: how to reverse sort lines in javascript 
Javascript :: react native android build location 
Javascript :: javascript continue with Nested Loop 
Javascript :: javascript Arrow Function as an Expressio 
Javascript :: javascript Assigning to a getter-only property is not allowed 
Javascript :: find the missing number javascript 
Javascript :: vite config js load env 
Javascript :: javascript read all cookies 
Javascript :: phaser wrap in rectangle 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =