Anchor tag Data attribute value is not returning correct value in react js

229 Views Asked by At

Hi I am passing an object to anchor tag like this

<a
data-message= {message.data}
id={`${this.uid}_primaryAction_${id}`}
href="#"
onClick={
  this.handlePrimaryActionClick
}
>
  <span>{primaryButtonText}</span>
</a>

and in handlePrimaryActionClick function I am accessing the data like below.

private handlePrimaryActionClick = (event: MouseEvent) => {
  event.preventDefault();
  const elem = event.target as HTMLElement
  const message = elem.parentElement.dataset.message;
};

But I am getting message as string , It should be object . Is anything wrong?

0

There are 0 best solutions below