Giter Site home page Giter Site logo

Comments (4)

zoltantothcom avatar zoltantothcom commented on May 27, 2024

Thank you for taking the time and reporting the issue. It's fixed now.

from react-clamp-lines.

acontreras89 avatar acontreras89 commented on May 27, 2024

@zoltantothcom to be completely honest, I was thinking the problem was the other way around. I feel like the component should render normally for empty strings. Is there a reason it isn't?

Why not change the guard in render to something like:

if (typeof this.props.text !== 'string') return null

from react-clamp-lines.

zoltantothcom avatar zoltantothcom commented on May 27, 2024

@acontreras89
The reasons I don't really want to render it for empty strings are:

  • since there is no text to clamp - the component is pointless and just pollutes the DOM and the virtual DOM
  • most importantly an event listener, involved in the responsive behavior, is being attached to a rendered component. So imagine, for example, a page with a list of 100 "articles" and the API endpoint that returns empty strings for half of them (like some of them have a summary that needs a clamp and the others don't) - so there will be 50 redundant event listeners on the page. Not good.

from react-clamp-lines.

acontreras89 avatar acontreras89 commented on May 27, 2024

@zoltantothcom I guess to me the library should focus on being intuitive and consistent more than addressing specific use cases.

the component [...] just pollutes the DOM

Having the component rendered for empty strings makes your resulting html consistent for all valid strings. Users can always choose not to use it for empty (or short) strings.

an event listener [...] is being attached

In cases where text fits without clamping, the listener is being attached too. It would be very nice to have this kind of optimization, but handling this scenario in this way made the component confusing to me.
Also, if you really want to get rid of the listener, you can still expand on the current condition a couple of lines below.

if (this.watch && this.props.text) {
  window.addEventListener('resize', this.debounced);
}

from react-clamp-lines.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.