An endless cycle occurs in the watcher when trying to refresh data from Vuex

I am facing an issue with a "dumb" component that receives props from a parent. The user has the ability to change a selector which triggers an action (using Vuex) to fetch new data. Once the new data is received, I need to pass it to the child component and re-render with the updated information. However, I keep encountering a warning in my watcher. Assistance would be greatly appreciated! :slight_smile:

export default {
  name: 'bubbles',
  props: {
    awesomeData: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      title: 'Best component ever'
    }
  },
  watch: {
    awesomeData (newData) {
      console.log('hello world')
      this.refreshSomethingAwesome(newData)
    }
  },
  methods: {
    refreshSomethingAwesome (newData) {}
  }
}

s

101 hello world
[Vue warn]: You may have an infinite update loop in watcher with expression "awesomeData"

I have tried a solution similar to this: Vuex Examples, but I am unable to get it to work properly. Any suggestions?

Answer №1

Discovered the root cause of the looping issue - turns out I was attempting to organize mutable data from the property, mistakenly assuming it was immutable.

let options = {
 children: newData.sort((a, b) => a.value - b.value)
}

Implemented a modification like this:

const sortedNewData = [...newData].sort((a, b) => a.value - b.value)

let options = {
 children: sortedNewData
}

Note: To avoid similar issues in my application, I am considering encapsulating my initial state in a Map using immutable.js.

import { Map, fromJS } from 'immutable'

const initialState = Map({
 awesomeData: fromJS([])
})

Informative read: alligator.io

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Executing a sequence of jQuery's $.when().then() functions

I am facing challenges in understanding how to properly sequence my functions, especially in relation to the $.when() method. function y() { defer = $.Deferred(); $.when(defer).then(console.log(defer.state())); } y(); <script src="https://ajax.go ...

When I toggle the password visibility and then click the submit button, it functions correctly

I am currently working on an application that combines Vue with Laravel. One of the Vue components I created is called UsersCreate. This component is responsible for gathering user data and sending it to a Laravel controller using axios. However, I have en ...

Can someone help me figure out how to make my Dropdown stay open when I highlight input, drag, and release

While working with the react bootstrap Dropdown component, I've encountered a specific behavior that is causing some trouble. To better illustrate the issue, I've attached some images. In my dropdown, there is an input filter box along with a li ...

$http({method}) is malfunctioning while $http.get is functioning properly

Issue Description: While working on my project, I encountered an issue where using $http({ method : 'GET', url : data : ..... param works fine for both GET and POST requests. However, when the same method is used in JSFiddle, it blocks my reques ...

CSS or jQuery: Which is Better for Hiding/Showing a Div Within Another Div?

Show only class-A at the top of the page while hiding all other classes (x,x,c). Hide only class-A while showing all other classes (x,x,c). Is it possible to achieve this? <div class="x"> <div class="y"> <div class="z"&g ...

Cached images do not trigger the OnLoad event

Is there a way to monitor the load event of my images? Here's my current approach. export const Picture: FC<PictureProps> = ({ src, imgCls, picCls, lazy, alt: initialAlt, onLoad, onClick, style }) => { const alt = useMemo(() => initial ...

Pagination issue in DRF and VueJS resulting in incorrect number of pages displayed

I've been experimenting with implementing pagination using DRF for the backend and VueJs for the frontend. Despite setting up the PageNumberPagination in my settings.py, I'm only able to display the first page number. In my articles viewset: cla ...

Troubleshooting the unresponsive Vue @change event within the <b-form-datepicker/> component

I am in the process of developing a website with both a select form and a datepicker form that will send an API request for data. I aim to have the data update dynamically whenever there is a change in either of these forms, thereby eliminating the need fo ...

Activate Bootstrap dropdown with an external button click

I am currently working with Bootstrap 5 dropdowns and I have a specific requirement. I want the button that triggers the dropdown to be located outside of its parent element (under A). Is there a way to achieve this using Jquery or JS? <div class=&quo ...

Manipulating the vueObject.dataItem variable in Vue JS directly affects the underlying Vue data item

I’ve encountered a troublesome behavior in my projects. Here is a simplified explanation of the issue at hand. I am eager to understand why this occurs and how I can prevent it. I have included Vue in the head section of my website: <script src="http ...

Trouble arising from authenticating in Laravel and Vue.js

I've successfully implemented authentication using Laravel as the backend and Vue.js as the frontend with the help of the jwt package. The registration, login, and logout requests are all functioning properly. The process involves the user entering t ...

Implementing MVC architecture in web development allows for the encryption of parameters sent

I have a scenario where I'm utilizing an ajax call to trigger my action method. The call involves sending two parameters, and I aim to secure/ encrypt these parameters before transmitting them to the action method, then decrypting those values within ...

What is the reason that an individual would stop another from executing by using $(document).ready(function() { ?

While I understand that it's supposed to be possible to run multiple $(document).ready(function() { on my page, for some reason I'm having trouble doing so. I appreciate those who have pointed out that it should work, but I'm really looking ...

Apollo client combines objects when the 'id' property is not specified

When I query data from my Apollo server, it follows a specific structure as shown below: hero { image { id name mimeType url } title description } welcome { image { id name mimeType ...

When accessing the innerHTML and outerHTML properties on an HTMLElement, they may return undefined without triggering

Task: My goal is to take an HTML string, make changes to certain attributes of image tags within it, and then return the modified HTML string. The function I have developed follows these steps: private resolveImagesInHTML (body: string): string { le ...

Is it possible to include HTML elements like <href> in Vue data?

My collection of data strings looks something like this: data(){ return(){ {name:"example", title:"exampleTitle", desc:"exampleDescription exampleDescription ....."}, {name:"example2", title:"example2Title", desc:"exampleDescripti ...

Is it possible to achieve efficient Autocompletion features within VS Code?

Just had my first experience with PhpStorm and I must say, I'm impressed, especially with the completion feature. Pressing Ctrl + Space on my Mac gives me relevant suggestions, like when I'm in a JS file and my project includes jQuery, I get Ele ...

Issue with sending POST and PUT requests using axios in combination with a vuetify datatable component in a vue.js application

I'm currently customizing a sample datatable from the vuetify website to suit my requirements by integrating axios to consume my API. The GET AND DELETE methods are functioning correctly, but I am facing challenges with the POST AND PUT methods. My se ...

Guide on setting a wait while downloading a PDF file with protractor

As I begin the download of a pdf file, I realize that it will take more than 2 minutes to complete. In order to verify if the file has successfully downloaded or not, I will need to wait for the full 2 minutes before performing any verification checks. C ...

Incorporate Ng-Survey multiple times within one component

Incorporating the ng-surveys template into my Angular application via has been successful. However, I encountered an issue where when using the template selector *ngFor to display multiple surveys on the same page, the browser treats all the surveys as id ...