Vue is alerting me that I cannot assign a reactive property to an undefined, null, or primitive value, specifically null

When retrieving data from Firebase, I am attempting to update the properties of the object being displayed on the UI. However, whenever I try to make any changes to the data, an error is thrown.
Error in v-on handler: "TypeError: Cannot use 'in' operator to search for 'cc' in null.

I am currently using Vue in development mode in conjunction with Firebase. Is there a key concept that I might be overlooking?

beforeCreate(){
sref.get().then(sc => {
      if (sc.exists) {
        console.log(sc.data()); // This logs the correct data
        this.school = sc.data(); // This works as well
        this.cc = sc.data().cc;  // This too
        this.name = sc.data().name;

However, when I execute

console.log(this.name)

In the created() hook, it returns undefined and any attempt to modify or update it results in an error:

[Vue warn]: Cannot set reactive property on undefined, null, or primitive value: null 
[Vue warn]: Error in v-on handler: "TypeError: Cannot use 'in' operator to search for 'cc' in null"

found in

---> <VSelect>
       <VForm>
         <VCard>

TypeError: Cannot use 'in' operator to search for 'cc' in null
    at Proxy.set 

Answer №1

I have identified my mistake in the template where I used v-model with this.school, this.name, and this.cc, resulting in warnings. Although I am not fully understanding how it all functions internally, I would appreciate any guidance towards helpful resources.

Answer №2

Encountering a similar issue while trying to set data using the v-model, I had the following setup:

<template>
      <v-text-field
        v-model="this.myVariable"
        :readonly="false"
        :disabled="false"
        persistent-hint
        outlined
      ></v-text-field>
</template>

data() {
    return {
      myVariable: "1",
    }
}

The problem was with the this keyword in the line specifying the v-model. Making the adjustment below helped me resolve the issue:

<template>
      <v-text-field
        v-model="myVariable"
        :readonly="false"
        :disabled="false"
        persistent-hint
        outlined
      ></v-text-field>
</template>

data() {
    return {
      myVariable: "1",
    }
}

Answer №3

Another unusual scenario occurs when your data function is enclosed within a mixin that is utilized by several scripts, one of which lacks the defined data property shool - resulting in the same error being thrown.

Answer №4

To easily solve this issue, consider implementing a v-if condition to check for the dataset within your v-for loop. You may also find it helpful to utilize the template tag for improved structure.

Answer №5

I encountered a similar issue in a different context, where I mistakenly used this.userDialogVisible (error) instead of userDialogVisible (correct):

<el-dialog
  title="Create a user"
  :visible.sync="userDialogVisible"
  :show-close="false"
  width="50%">
  <!--      dialog content-->
  <span>This is a message</span>
  <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="userDialogVisible=false">Confirm</el-button>
    <el-button @click="userDialogVisible=false">Cancel</el-button>
  </span>
</el-dialog>

The error message states: "TypeError: Cannot use 'in' operator to search for 'userDialogVisible' in null".

This occurs because this.userDialogVisible is trying to access a global property during the beforeCreate stage when it is still null. It gets assigned a value during the created stage.

When referencing properties like this.xxx, this.$xxx, or this.Ωxxx in the beforeCreate stage, Vue.js will only look for a global property named xxx.

In situations involving data retrieval from a backend server (such as Firebase), it is recommended to perform these actions in the created or mounted stages, rather than beforeCreate, unless working with global properties intentionally.

You cannot access local properties defined in data() using this.xxx in the beforeCreate stage.

Further information

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

Testing event emitters in node.js: a step-by-step guide

Imagine the scenario where I need to create a basic task. However, I also need to develop a test that validates the following criteria: The task should emit an object. The emitted object must have a property named "name". I am utilizing mocha and chai e ...

Exploring the Differences Between Next.js Script Components and Regular Script Tags with async and defer Attributes

Can you explain the distinctions between the next js <Script /> component rendering strategies such as afterInteracive, beforeInteractive, and lazyLoad, as opposed to utilizing a standard <script /> tag with attributes like async and defer? ...

Can you explain the process of extracting images from JSON data using AJAX and jQuery?

Hello, I'm looking for guidance on incorporating jquery with AJAX to fetch images from a JSON file and showcase them on my website. Below is the code snippet I have put together. function bookSearch(){ var search = document.getElementById('sea ...

Exploring Angular's Dependency Injection

How can I verify that a module has properly loaded its required dependencies? I've added ngAnimate to the module definition, but it doesn't appear to be functioning within the application when it runs. The environment I'm navigating is quite ...

The call stack reached its maximum size while attempting to send a post request in an Express application

'Error Occurred: RangeError: Maximum Call Stack Size Exceeded' When Making a Post Request in Node.js with Express and body-parser As a beginner in the world of node.js, my journey took a challenging turn while following along with video #30 from ...

How to effectively manage multiple stylesheet links in React Native Expo development

Hello, my name is Antika. I recently embarked on a coding journey and have been focusing on learning HTML/CSS/JS along with the basics of React. As a beginner developer, my current project involves creating a Study planner app for myself using React Native ...

The React component is experiencing a delay in its updates

I've been experiencing delayed updates when using React.useEffect(). Can anyone shed some light on why this might be happening? function Process(props) { const [results, setResults] = React.useState({ number: "", f: {} }); let ...

What is the best way to merge multiple statements into one before passing them into a JavaScript method?

I am faced with several javascript statements like the ones listed below: $('#' + xxx_slot_name1).children().remove(); $('#' + xxx_ad_slot_name2).children().remove(); $('#' + xxx_ad_slot_name3).children().remove(); $('#& ...

Tips for sending a structured search query to the findOne() function in MongoDB with Node.js

I have a Restful service built with node.js that takes user input to create a query string for MongoDB. However, whenever I try to pass this query to findone() in MongoDb and call the service, it displays a "query selector must be an object" message in the ...

Using ngrx to automatically update data upon subscription

Background The technology stack I am using for my application includes Angular 4.x, ngrx 4.x, and rxjs 5.4.x. Data is retrieved from a websocket as well as a RESTful API in order to share it between multiple components through ngrx. Currently, data is ref ...

Using jQuery for communication between a parent and a popup tab

There have been numerous discussions on the topic of communication between a popup and its parent using window.opener.$('#myDiv'). However, once a popup is launched, how can the parent target and manipulate a specific div within the popup? ...

Tips for creating a seamless horizontal scrolling effect in Angular when hovering (automatically)

One of the components I'm working on features a gallery with an X axis orientation. <div class="gallery"> <div (mouseenter)="scrollTo('left', $event)" (mouseleave)="clearIntervalRepeater()" class="left"></div> < ...

Checkbox Trouble: Troubleshooting AJAX Integration

One of the requirements I have is to implement a checkbox list that updates the page via AJAX when one of the checkboxes is clicked. $(document).on("click", ".selectlist input", update_results); My client has requested that one of the checkboxes be pre-s ...

Is there a way to determine which 'a href' link was selected on the previous webpage?

Being relatively new here, I have often visited Stack Overflow to find answers to questions that I have, only to discover that most of them have already been asked before (heh). However, I am facing a dilemma now. I have a homepage with two div elements ...

What is the best way to convert a string to JSON format using Javascript?

I've been working on retrieving the results of a PHP query into a JavaScript object. However, I encountered an error message in the console saying Uncaught SyntaxError: Unexpected token { in JSON at position 66. I understand that this error occurs bec ...

Develop an array of unique objects with multiple dimensions, ensuring no duplicates are included

Seeking assistance for the following task: I am trying to create a new multidimensional array of objects based on an existing array of objects: [ {number:111, connectedNumber: 112, ...}, {number:112, connectedNumber: 111, ...}, {number:113, connectedNumbe ...

Modifying the value of a React input component is restricted when the "value" field is utilized

I'm currently utilizing material-UI in my React application. I am facing a challenge where I need to remove the value in an input field by clicking on another component. The issue arises when using the OutlinedInput component with a specified value. ...

What can be done to avoid causing other elements to blur when clicking a button?

Imagine a scenario where there is a textarea and a button present. If the button is clicked, typically the textarea will blur. However, in this case, I do not want that to happen. I am seeking advice on how to prevent the textarea from blurring u ...

React: segregate state and functions away from the view, although encountering an excess of props to transmit

Experimenting with a new approach that keeps state definition and functions separate from components. For example: // Display.js const Display = (props) => { const { data, setData, action } = props; ... return <div>...</div>; } // Di ...

What causes setInterval to create an endless loop when used inside a while loop in JavaScript?

I attempted to initiate a delayed "one" call or a "one or two?" question, but instead of working as expected, the function continued running indefinitely. Surprisingly, everything worked perfectly fine without using setInterval. quester2() function quest ...