Explode doesn’t work with a string coming from JS

// js
<script>
    // when button clicked
    let tags = 'foo,bar';
    elem.innerHTML += `<x-post tags="${tags}"></x-post>`
</script>
// post.blade.php
@php
    var_dump($tags); // string(9) "foo,bar"
    $tags = explode(',',$tags); // exploding
    echo "<br>";
    var_dump($tags); // array(1) { [0] => string(9) "foo,bar"} 
@endphp

How can i fix it? And why this is working correctly when i writing tags=”foo,bar” ?

Expecting: array with foo and bar.

Tryed: JSON.stringify(), array, array with JSON.stringify().

Actually, I’m sending a post with tags via ajax so that they load after clicking on the button, like pagination. It works without tags, but such a problem has arisen with them.

Maybe you know how i can normally send an array to a blade component like in php?

example