I have this element:
<div className={`my_container ${theme} ${isSpanishLanguage && 'spanishLanguage'} ${isEnglishLanguage && 'englishLanguage'}`}></div>
And I ge the error that my line is too long. How can I split this line into multiple lines to avoid getting this error ?
3
Answers
Write a function like:
And call it with the appropriate params (even outside of jsx), or use a package like clsx.
You could just rewrite that line like this:
However you shouldn’t be doing this manually, you should be relying on a tool like
prettier
to do this for you automatically upon saving your work.Or if you could just disable the
eslint
rule that complains about the length of your code line.It is a lint error but I would like to suggest you one library for joining classes in your react app systematically.
I would suggest using https://www.npmjs.com/package/classnames package. It allow you to join classes conditionally.
So the approach would be like