Skip to content
Advertisement

Using boolean-value of attributes in JSX

I have a React.js project. I want to use data-picker plugin which require this style of input-attributes:

JavaScript

But webpack doesn’t compile the app, when true is without quotes. Plugin doesn’t work, when true with quotes. What I should do?

UPD.

Yes, I run picker in componentDidMount() It works, but displaying only date, without time.

JavaScript

But data-enable-time="true" doesn’t work.

Advertisement

Answer

According to the HTML spec, there is no difference between data-enable-item=true and data-enable-item="true". They will function exactly the same in browsers. Because HTML attributes without quotes are practically never used and can lead to a number of issues, React always uses quoted attributes.

In the snippet below you can check that they do indeed have the exact same effect.

I suspect your plugin not working is probably because you are loading your plugin the wrong way, and not because of the data attribute style. Are you sure you’re only starting the date picker after the component has been mounted (for example, in componentDidMount)?

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement