Re-render JS on a Live view update - how to?

Hi,
if I have this code in a template:

<script>
<%= if is_nil(@value) do %>
        console.log("hello");
        # custom functions
<% else %>
    console.log("hello2");
    # custom functions
<% end %>
</script>

I can see in the inspect elements the following behaviour: on mount if value is nil it logs into the JS console the right string. If value of @value is changed via a socket.update/3, the <script> elements are changed correctly, it shows <script> console.log("hello2") </script>, but that log is not being rendered, there is no new “messages” in the JS console. Only the html side, if I may say so, is re-rendered. What could be the right way to achieve what I want? Sorry for my bad explanation

This is not going to work with inline scripts. Consider another method like hooks or event handlers + dispatching event to trigger JS from a LV.

3 Likes