• 1 Post
  • 114 Comments
Joined 1 year ago
cake
Cake day: July 3rd, 2023

help-circle




  • Very interesting. Actually the part you mention about there being an initial 'btn' class is a good point. Using arrays and joining would be nice for that. I wish more people would chime in. Because between our two examples, I think mine is more readable. But yours would probably scale better. I also wonder about the performance implications of creating arrays. But that might be negligible.


  • Ok how about this then, I frequently do something like this:

    let className = 'btn'
      if (displayType) {
        className += ` ${displayType}`
      }
      if (size) {
        className += ` ${size}`
      }
      if (bordered) {
        className += ' border'
      }
      if (classNameProp) {
        className += ` ${classNameProp}`
      }
    

    How would this be made better with a functional approach? And would be more legible, better in anyway?