JSFiddle - React, Tailwind, and code Playground

HTML

<svg width="100" height="50">
    <path id="path1" d="M 10 10  L 40 20  20 40" fill="none" stroke="blue" stroke-width="2"  />
</svg>
<button type="button" id="btn">Change</button>

JavaScript

var btn = document.getElementById('btn');
btn.onclick = function () {
    var path = document.getElementById('path1');
    var animate = document.createElementNS("http://www.w3.org/2000/svg","animate");
    animate.setAttribute('attributeName', 'd');
    animate.setAttribute('dur', '1s');
    animate.setAttribute('fill', 'freeze');
    animate.setAttribute('values', 'M 10 10  L 40 20  20 40; M 30 10  L 10 40  40 30');
    path.appendChild(animate);
    animate.beginElement();
}