Skip to content

Latest commit

 

History

History
14 lines (11 loc) · 543 Bytes

reactivly-push-element-to-array.md

File metadata and controls

14 lines (11 loc) · 543 Bytes

Reactivly Push Element to Array

Sometimes when using a reactive frontend framework (svelte, vuejs), pushing elements to arrays using the .push method does not trigger reactive change. There are however another way of pushing elements that will force the reactive change to take place. This way relies on creating a new array and assinging it to the same variable as follows:

let arr = ["Banana", "Orange", "Apple"];

// The new forced assignment below triggers many reactive based models
arr = [...arr, "Avocado"];