Expression in the html attribute?

reasonreact

#1

Hi all

Is it possible to write an expression in jsx attribute? For example:

<li className="nav-item {active}" title={title}/>

active is an expression.

Thanks


#2

How about…

<li className=("nav-item " ++ active) title=title/>

#3

Alsot, It possible to write

let active = "nav-item-active";

<li className={j|nav-item $active|j} title="title" />;

The interpolated must be only a variable. Not expression

https://bucklescript.github.io/docs/en/interop-cheatsheet.html#string-unicode-interpolation


#4

If you are doing a lot of conditional className stuff you might want to check out this small/simple but awesome library from @alexfedoseev… https://github.com/alexfedoseev/re-classnames