Hello I'm making a comment section for my website which works but when I push an object to an array my {#each}
block doesn't update here is this block of code
{#each commentsScript as { userName, rating, comment }, i}
<div class="flex">
<div class="w-1/4">
<h5>{userName}</h5>
<h5>{rating}</h5>
</div>
<div class="w-3/4">
<p>{comment}</p>
</div>
</div>
{/each}
In my script section, I push a new comment to an array and it does show up after I refresh the page but I want to rerender it as soon as the user leaves a comment so the user would see hes/her own comment so is there any way I can rerender it?
https://svelte.dev/tutorial/updating-arrays-and-objects
You have to assign commentsScript = commentsScript
, which would be redundant normally, but that is how svelte works. This is true if you are using push function on array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With