Check out example codes for "attribute drupal 8". It will help you in understanding the concepts better.

Code Example 1

<div{{ attributes.addClass('my-class') }}></div>

{% set classes = [ 'red', 'green', 'blue' ] %}
<div{{ attributes.addClass(classes).removeClass('green') }}></div>

<div{{ attributes.setAttribute('id', 'myID') }}></div>
<div{{ attributes.removeAttribute('id') }}></div>
<div style="{{ attributes.style }}"></div>

{% if attributes.hasClass('myClass') %}
  {# do stuff #}
{% endif %}

{% if attributes['data-my-data'] %}
  {# do stuff #}
{% endif %}

<div class="myclass {{ attributes.class }}"{{ attributes|without('class') }}></div>

{% set my_attribute = create_attribute() %}
{%
  set my_classes = [
	'your class'
  ]
%}
<div{{ my_attribute.addClass(my_classes).setAttribute('id', 'myUniqueId') }}>
  {{ content }}
</div>

Learn ReactJs, React Native from akashmittal.com