Tips for adding a new key to an object already stored in session storage

I'm looking to make a change in the following code snippet

addToFilterCriteriaTree(componentData) {
        let id = componentData.props.data.id;
        this.state.filterCriteriaTree[id] = componentData.criteria; 
}

My goal is to replace using state with creating an object called 'filterCriteriaTree' using setStorage and adding a new key to it

Answer №1

By adjusting the parameters, I have enhanced the code so that only the necessary data is provided to the function for it to execute its task rather than passing the entire object.

updateFilterCriteriaTree(id, criteria) {
  let existingFilterCriteriaTree = JSON.parse(sessionStorage.getItem('filterCriteriaTree')) || {};
  existingFilterCriteriaTree[id] = criteria;
  sessionStorage.setItem('filterCriteriaTree', JSON.stringify(existingFilterCriteriaTree);
}

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

Sequelize encountered an error: getaddrinfo ENOTFOUND (even though the address is correct)

I've encountered some Sequelize errors while attempting to deploy a site I developed using Angular and Express/Sequelize. Here's the issue: Everything works perfectly on my local WAMP server, connecting to the local database without any problems ...

Using React JS to iterate over an array and generate a new div for every 3 items

It's a bit challenging for me to articulate my goal effectively. I have a JSON payload that looks like this: { "user": { "id": 4, "username": "3nematix2", "profile_pic": &qu ...

Customizing the appearance of table column labels in BootstrapVue

Seeking help with formatting my table labels to display as defined in the code. Currently, the labels only capitalize the first character of the word and ignore the rest. Any suggestions on how to achieve the desired value for label display? Currently, IP ...

Generating a user interface (UI) by utilizing an EDMX file

What exactly is an EDMX file and what function does it serve? Is it possible to generate a UI screen using an EDMX file? If so, what are the steps involved in doing so? Thank you for your help ...

What steps should I take to ensure that the proper link is loaded and opened when the loop is clicked?

I've been working on a script to display the top 25 posts from reddit and have their respective links open in a sliding div below. However, I'm running into an issue where the script outputs the same post for every item in the loop. I understand ...

What is the best method to modify the accurate phone number within my script?

I need help with a text format script. link HTML CODE: <label for="primary_phone">Primary Phone Number<span class="star">*</span></label> <br> <input type="text" name="primary_phone" id="primary_phone" class="_phone requ ...

Choosing the Angular5 model

I'm currently working with an Angular5 project that has a <select> element bound to an array of customers. Here's the code snippet: <select class="form-control" [ngModel]="record.customer_id" (ngModelChange)="setCustomer($event)" name=" ...

Utilizing React Hooks to toggle the aria-expanded boolean value

I'm presently focusing on enhancing accessibility for a web application utilizing React and Ant Design's Select component. The value of aria-expanded is currently set to 'false' string. My goal is to utilize React's useState to to ...

Interested in integrating server side JavaScript with your Android application?

Running a simple web page on a Raspberry Pi to toggle the board's LED with the click of a button. The button triggers a JavaScript function that controls the LED. Now, I want to be able to call this script from a button in an Android application... B ...

Invoking a JQuery function within a repeater component

Is it possible to call a jQuery function inside a repeater? The issue is that I want to toggle the div when clicking on the link button. It seems like the first jQuery function may not be suitable for this case. There could also be a problem with the tab ...

Utilizing the power of Ajax for enhancing table sorting and filtering functionality

Having an issue using JQuery tablesorter to paginate a table with rows fetched from the database. //list players by points (default listing) $result=mysql_query("select * from players order by pts_total") or die(mysql_error()); echo "<table id='li ...

Ways to categorize items using JQuery based on their hierarchical structure

I am looking to organize the following HTML content: <h2>State the Issue  </h2> <h3>Provide information about your objective</h3> <h3>Share any error messages received</h3> <h2>Outline Your Attempts  ...

Experiencing difficulties with loading Facebook wall feed JSON data

Struggling to integrate a Facebook wall feed using jQuery on my website's client side. Utilizing this URL for the Facebook request: Attempted approaches so far: 1. $.getJSON('http://www.facebook.com/feeds/page.php?format=json&id=407963083 ...

Using JQuery toggleclass to add transitioning effects to a :after element

I'm using the toggleClass function to add the class .expend to a div with an ID of #menu, which increases the height of the menu from 100px to 200px with a smooth transition effect. I also have a pseudo-element #menu:after for aesthetic purposes. My ...

Retrieving the data from an Angular website using a curl command

Currently, I am facing an issue with my Angular 2 application running on Google Earth. The problem arises as Google Earth uses an outdated version of Chrome that is not compatible with Angular 2. To tackle this obstacle, I need to find a way to initiate th ...

Attempting to use the getCurrentUrl() function to retrieve the current URL and subsequently opening it in a new tab

I am attempting to retrieve a URL and open it in 3 new tabs, but encountering errors in the process: browser.getCurrentUrl().then(url => { browser.actions().keyDown(protractor.Key.CONTROL).sendKeys('t').perform(); browser.sleep ...

Querying MySQL database for variable values in JavaScript

I have a JavaScript file on my website that carries out calculations. Currently, my variables are defined as global variables in another JavaScript file. What I would like to do is make these variables dynamic by pulling their values from a MySQL database ...

The result from noty.js is coming back as undefined

Recently, I started using noty.js but I encountered an issue while trying to execute the basic example for creating a noty. The error message I kept receiving was: Uncaught TypeError: Property 'noty' of object function (a,b){return new e.fn.init ...

Invoke a function from a different vue.js component using the this.$refs property

I'm facing an issue with triggering a sibling element. What I've tried so far <b-img @click="callFileLoader"/> <b-file type="file" ref="fileUploader"></b-file> ... methods:{ callFileLoader () { this.$refs.fileUploader.c ...

The framer-motion library does not immediately unmount the DOM node after the exit animation completes

I recently developed an animated modal container that is working well for the most part. However, I have encountered a minor issue where after the exit animation, there is a delay in unmounting the modal (during this time, clicking elsewhere does not work) ...