Mat Checkbox and Mat Radio not displaying properly in Angular Material 17.2.0

Angular material not displaying checkboxes and radio buttons properly im using angular 17 and angular material 17

"@angular/material": "17.2.0",

here is my code

<h1>Radio Buttons</h1>
<mat-radio-group aria-label="Select an option">
  <mat-radio-button value="1">Option 1</mat-radio-button>
  <mat-radio-button value="2">Option 2</mat-radio-button>
</mat-radio-group>

<br> <br> <br> <br>
<h1>Check Boxes</h1>

<section class="example-section">
  <mat-checkbox class="example-margin">Yes</mat-checkbox>
  <mat-checkbox class="example-margin">No</mat-checkbox>
</section>

here is the outcome
enter image description here

You can see that even the shadow for these elements are displaced from the actual elements

I have tried updating my angular material

Front-end problem, the page doesn’t refresh something wrong with react dom

I’m making this website and its a clone of amazon. i want my code to go to the other page just by clicking for my case i want it to go to the checkout page when i press in the baskeT, go back from that page just by clicking on the logo

i wanted to use react-dom for this. I mean at fist everything seemed fine then i wanted to add the moving around the page just by clicking on pictiures but it doesn’t loading on its own

I tried to the basket too it does the same so in the browser link i see that it changes back to other page but for me i have to press refresh manually how can i just make it refresh the page without just by clicking on the logos

this is app.js

import React from 'react';
import './App.css';
import Header from './Header';
import Home from './Home';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import Checkout from './Checkout';

function App() {
  return (
    <Router>
      <div className="app">
        <Header />

        <Switch>
          <Route path="/checkout">
            <Checkout />
          </Route>
          <Route path="/">
            <Home />
          </Route>
        </Switch>
      </div>
    </Router>
  );
}

export default App;

import React from 'react';
import './Header.css';
import SearchIcon from '@mui/icons-material/Search';
import ShoppingBasketIcon from '@mui/icons-material/ShoppingBasket';
import { Link } from 'react-router-dom';

function Header() {
  return (
    <div className="header">
      <Link to="/">
        <img
          className="header__logo"
          src="https://pngimg.com/uploads/amazon/amazon_PNG11.png"
          alt="Amazon Logo"
        />
      </Link>
      <div className="header__search">
        <input className="header__searchInput" type="text" />
        <SearchIcon className="header__searchIcon" />
        {/* Logo */}
      </div>

I feel like problem is between these but if someone needs more of the project ill be happy to share

In Webpack, how do I expose vendor JS?

Outside of Webpack, I have compiled and minified custom modules and vendor modules together. The result is a JS file that is basically a concatenation of the separate JS files. If I use a third-party vendor plug-in like autoComplete.js, I can access its functions in the console by typing “autocomplete,” which renders the function object. The same applies to other vendor modules as well.

If I use Webpack to compile modules, I can’t access the autoComplete function in the console as before. How can I expose JS in this way so its functions are accessible? If I look at the rendered JS from Webpack, I can’t even find a function named autoComplete.

I have a main.ts file I am using as the entry to import the Sass and JS. The JS files are placed in their own src folder. I have attempted adjusting some of the module.exports settings in the config but I’m not sure how to tell Webpack to bundle these in a way that exposes the functions globally like the non-Webpack build.

Change value of getAttribute when null

I am creating a document that contains the selected answers from a quiz.

I am running into trouble when some questions are skipped based on previous answers. When this occurs, I receive,

Uncaught TypeError: Cannot read properties of null (reading
‘getAttribute’)

How can I amend my code to pass a value of “N/A” when the field is skipped? I have tried the following with no avail.

var oldValue = document.querySelector(".quiz_selected_answer input[name='question-2']").getAttribute('data-value');
            var newValue; 
            if (!oldValue) { 
                newValue =  
                "N/A"; 
            } else { 
                newValue = oldValue; 
            }

Thank you community for your help. It is appreciated.

Copy values from XML element to create a new element with combined new value

I have this XML with multiple products and I want to add a new element with the values of other elements. I want to add a new element to each titled . This should include the values of ProductOption, PurchaseOption, Quantity. Example should look like <sku>price-each-an-order-250-499</sku>.
I am open to different technologies, like command line sed, bash etc.., php, python, javascript.

Input XML

<Catalog>
    <Product>
        <Number>82508</Number>
        <Title>Product Title</Title>
        <Description>description</Description>
        <Variations>
            <!-- An Order; no imprint -->
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>An Order</PurchaseOption>
                <Quantity>250-499</Quantity>
                <MinQuantity>250</MinQuantity>
                <MaxQuantity>499</MaxQuantity>
                <Price>1.09</Price>
            </Variation>
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>An Order</PurchaseOption>
                <Quantity>500-999</Quantity>
                <MinQuantity>500</MinQuantity>
                <MaxQuantity>999</MaxQuantity>
                <Price>0.95</Price>
            </Variation>
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>An Order</PurchaseOption>
                <Quantity>1000-2499</Quantity>
                <MinQuantity>1000</MinQuantity>
                <MaxQuantity>2499</MaxQuantity>
                <Price>0.93</Price>
            </Variation>
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>An Order</PurchaseOption>
                <Quantity>2500-4999</Quantity>
                <MinQuantity>2500</MinQuantity>
                <MaxQuantity>4999</MaxQuantity>
                <Price>0.87</Price>
            </Variation>
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>An Order</PurchaseOption>
                <Quantity>5000</Quantity>
                <MinQuantity>5000</MinQuantity>
                <MaxQuantity></MaxQuantity>
                <Price>0.84</Price>
            </Variation>
            <!-- A Quote; no imprint -->
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>A Quote</PurchaseOption>
                <Quantity></Quantity>
                <MinQuantity></MinQuantity>
                <MaxQuantity></MaxQuantity>
                <Price>0.00</Price>
            </Variation>
            <!-- A Sample; no imprint -->
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>A Sample</PurchaseOption>
                <Quantity>1</Quantity>
                <MinQuantity>1</MinQuantity>
                <MaxQuantity>1</MaxQuantity>
                <Price>0.00</Price>
            </Variation>
        </Variations>
    </Product>
</Catalog>

Expected Output

<Catalog>
    <Product>
        <Number>82508</Number>
        <Title>Product Title</Title>
        <Description>description</Description>
        <Variations>
            <!-- An Order; no imprint -->
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>An Order</PurchaseOption>
                <Quantity>250-499</Quantity>
                <MinQuantity>250</MinQuantity>
                <MaxQuantity>499</MaxQuantity>
                <Price>1.09</Price>
                <Sku>price-each-an-order-250-499</sku>
            </Variation>
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>An Order</PurchaseOption>
                <Quantity>500-999</Quantity>
                <MinQuantity>500</MinQuantity>
                <MaxQuantity>999</MaxQuantity>
                <Price>0.95</Price>
                <Sku>price-each-an-order-500-999</sku>
            </Variation>
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>An Order</PurchaseOption>
                <Quantity>1000-2499</Quantity>
                <MinQuantity>1000</MinQuantity>
                <MaxQuantity>2499</MaxQuantity>
                <Price>0.93</Price>
                <Sku>price-each-an-order-1000-2499</sku>
            </Variation>
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>An Order</PurchaseOption>
                <Quantity>2500-4999</Quantity>
                <MinQuantity>2500</MinQuantity>
                <MaxQuantity>4999</MaxQuantity>
                <Price>0.87</Price>
                <Sku>price-each-an-order-2500-4999</sku>
            </Variation>
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>An Order</PurchaseOption>
                <Quantity>5000</Quantity>
                <MinQuantity>5000</MinQuantity>
                <MaxQuantity></MaxQuantity>
                <Price>0.84</Price>
                <Sku>price-each-an-order-5000</sku>
            </Variation>
            <!-- A Quote; no imprint -->
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>A Quote</PurchaseOption>
                <Quantity></Quantity>
                <MinQuantity></MinQuantity>
                <MaxQuantity></MaxQuantity>
                <Price>0.00</Price>
                <Sku>price-each-a-quote</sku>
            </Variation>
            <!-- A Sample; no imprint -->
            <Variation>
                <ProductOption>Price Each</ProductOption>
                <PurchaseOption>A Sample</PurchaseOption>
                <Quantity>1</Quantity>
                <MinQuantity>1</MinQuantity>
                <MaxQuantity>1</MaxQuantity>
                <Price>0.00</Price>
                <Sku>price-each-a-sample-1</sku>
            </Variation>
        </Variations>
    </Product>
</Catalog>

Not sure what to use to accomplish this. Any examples or tutorials would be helpful.

How can I actually edit a HTML element with JavaScript, just like you do in the dev console by clicking “Edit as HTML”

Disclaimer: I am a massive beginner

So I was having fun with JavaScript and I wondered if instead of using innerHTML if you wanted to change the text or style.color for css fun or whatever (I am a beginner to all of this) you can actually rewrite the element, like if I wanted to target the title of this question as an example, should look probably something like this in the html:

<a href="/questions/78202361/how-can-i-actually-edit-a-html-element-with-javascript-just-like-you-do-in-the" class="question-hyperlink">How can I actually edit a HTML element with JavaScript, just like you do in the dev console by clicking "Edit as HTML"</a>

and lets say with JavaScript I want to edit the color, so adding […]just <span style="color:red">like</span> you do in […] (I used […] to skip some text cause of my long question)

Basically my question is if I can retype a element completely within a script, or maybe you have to cut it, change it, and then create a new one.

I didn’t find the answer nowhere else or maybe I’m just using the wrong terms

Using two buttons with onclick events that continuously change each other?

This is what I’m trying to accomplish:

Two buttons (left and right). The left button starts off with a cursor of “not-allowed” on hover (indicating starting off the left button should not be clicked). When the right button is clicked, this turns the right button’s cursor to “not-allowed” on hover indicating it shouldn’t be clicked after being clicked once, while simultaneously making the left button’s cursor “arrow” on hover indicating the left button is now open to be clicked after the right button is clicked.

I have written some code using javascript and using “onclick events”. This code is not what I want, but gives you a visual of what I’m trying to accomplish as I explained above:

<body>
  <button id="slide-arrow-prev" onclick="prev()"> < </button>
  <button id="slide-arrow-next" onclick="next()"> > </button>
</body>


<script>
  function prev() {
    document.getElementById("slide-arrow-prev").style.cursor = "not-allowed";
    document.getElementById("slide-arrow-next").style.cursor = "arrow";
  }

  function next() {
    document.getElementById("slide-arrow-next").style.cursor = "now-allowed";
  }
</script>

Basically, the idea is an image carousel that slides when the left and right buttons are pushed. I’m trying to mimic the carousel used on the homepage of aliexpress (you can look there for reference). Once the carousel reaches it’s slide limit, the cursor of the left/right buttons are “not-allowed” indicating they can’t slide anymore images.

I tried using an event listener but not really sure if I was supposed to, so I took that out.

How can I write this please using html, javascript and/or CSS?

there are table that appears after clicking on the icon. i need to parse the level of the CO

there are divs like that:

<div class="awesome-marker-icon-green awesome-marker leaflet-zoom-animated leaflet-interactive" tabindex="0" style="margin-left: -17px; margin-top: -42px; width: 35px; height: 45px; transform: translate3d(79px, 254px, 0px); z-index: 254; outline: none;"><i style="" class=" ion ion-ios-close  icon-black"></i></div>
<div class="awesome-marker-icon-red awesome-marker leaflet-zoom-animated leaflet-interactive" tabindex="0" style="margin-left: -17px; margin-top: -42px; width: 35px; height: 45px; transform: translate3d(144px, 276px, 0px); z-index: 276; outline: none;"><i style="" class=" ion ion-ios-close  icon-black"></i></div>
<div class="awesome-marker-icon-red awesome-marker leaflet-zoom-animated leaflet-interactive" tabindex="0" style="margin-left: -17px; margin-top: -42px; width: 35px; height: 45px; transform: translate3d(146px, 268px, 0px); z-index: 268;"><i style="" class=" ion ion-ios-close  icon-black"></i></div>
<div class="awesome-marker-icon-beige awesome-marker leaflet-zoom-animated leaflet-interactive" tabindex="0" style="margin-left: -17px; margin-top: -42px; width: 35px; height: 45px; transform: translate3d(14px, 218px, 0px); z-index: 218;"><i style="" class=" ion ion-ios-close  icon-black"></i></div>
<div class="awesome-marker-icon-green awesome-marker leaflet-zoom-animated leaflet-interactive" tabindex="0" style="margin-left: -17px; margin-top: -42px; width: 35px; height: 45px; transform: translate3d(29px, 212px, 0px); z-index: 212;"><i style="" class=" ion ion-ios-close  icon-black"></i></div>

and so on. after clicking one of them appears a table:


<div class="leaflet-pane leaflet-popup-pane"><div class="leaflet-popup  leaflet-zoom-animated" style="opacity: 1; transform: translate3d(145px, 244px, 0px); bottom: -7px; left: -171px;"><div class="leaflet-popup-content-wrapper"><div class="leaflet-popup-content" style="width: 301px;">
 2024-03-21 20:00:00<table style="border-collapse:collapse;" class="table_2933" border="1">
<caption><b><span style="color:#000000">ПНЗ№4 : Кустанай, ул. Маяковского-Волынова </span></b></caption><tbody><tr>
</tr></tbody><caption id="footer" align="bottom"><b><span style="color:#000000">Модель SILAM, адаптированная для Казахстана по ссылке:</span></b> <a href="http://silam.fmi.fi/roux/KAZ/">http://silam.fmi.fi/roux/KAZ/</a></caption>
<colgroup><col width="100">
<col width="100">
<col width="100">
<col width="100">
</colgroup><thead>
<tr>
  <th colspan="1" id="tableHTML_second_header_1" style="height:30px;background-color: #e6e6e6;font-size:12px;text-align:center;"></th>
  <th colspan="4" id="tableHTML_second_header_2" style="height:30px;background-color: #e6e6e6;font-size:12px;text-align:center;">Концентрация, мкг/м3</th>
</tr>
<tr>
  <th id="tableHTML_header_1" style="height:30px;background-color: #e6e6e6;text-align:center;padding-left:5px;padding-right:5px;">Показатели</th>
  <th id="tableHTML_header_2" style="height:30px;background-color: #e6e6e6;text-align:center;padding-left:5px;padding-right:5px;">Фактическое значение</th>
  <th id="tableHTML_header_3" style="height:30px;background-color: #e6e6e6;text-align:center;padding-left:5px;padding-right:5px;">Прогноз 24 часа</th>
  <th id="tableHTML_header_4" style="height:30px;background-color: #e6e6e6;text-align:center;padding-left:5px;padding-right:5px;">Прогноз 48 часов</th>
</tr>
</thead>
<tbody>
<tr>
  <td id="tableHTML_column_1" style="text-align:center;">CO</td>
  <td id="tableHTML_column_2" style="text-align:center;">462</td>
  <td id="tableHTML_column_3" style="text-align:center;">264</td>
  <td id="tableHTML_column_4" style="text-align:center;">268</td>
</tr>
<tr>
  <td id="tableHTML_column_1" style="text-align:center;">NO</td>
  <td id="tableHTML_column_2" style="text-align:center;">45</td>
  <td id="tableHTML_column_3" style="text-align:center;">0</td>
  <td id="tableHTML_column_4" style="text-align:center;">0</td>
</tr>
<tr>
  <td id="tableHTML_column_1" style="text-align:center;">NO2</td>
  <td id="tableHTML_column_2" style="text-align:center;"><span style="background-color:#ff0000">485</span></td>
  <td id="tableHTML_column_3" style="text-align:center;">4</td>
  <td id="tableHTML_column_4" style="text-align:center;">2</td>
</tr>
<tr>
  <td id="tableHTML_column_1" style="text-align:center;">SO2</td>
  <td id="tableHTML_column_2" style="text-align:center;">6</td>
  <td id="tableHTML_column_3" style="text-align:center;">6</td>
  <td id="tableHTML_column_4" style="text-align:center;">3</td>
</tr>
</tbody>
</table></div></div><div class="leaflet-popup-tip-container"><div class="leaflet-popup-tip"></div></div><a class="leaflet-popup-close-button" href="#close">×</a></div></div>

i need to parse level of the CO, NO, NO2, and SO2. the problem is that everything is gone after exiting the table and there is no stable element that i can use. http://ecodata.kz:3838/app_dem_visual/ to know better

i have tried that, i think that is the best i have

const puppeteer = require('puppeteer');


(async () => {
  try {
    const browser = await puppeteer.launch({ headless: false });
    const page = await browser.newPage();
    await page.goto('http://ecodata.kz:3838/app_dem_visual/');

    await page.waitForSelector('.ico');

    const icons = await page.$$eval('.ico', icons => icons.map(icon => icon.outerHTML));

    
    const popups = [];
    for (const icon of icons) {
      
      await page.setContent(icon);
      
      try {
        await page.waitForSelector('.leaflet-popup-content', { timeout: 10000 });

        const popupText = await page.$eval('.leaflet-popup-content', popup => popup.textContent);
        popups.push(popupText);
      } catch (error) {
        console.error('Error while waiting for popup:', error);
      } 
    }

    console.log(popups);

    await browser.close();
  } catch (error) {
    console.error('Error during script execution:', error);
  }
})();

An HTML Link Element (“a”) Refuses to Attach Itself to Event Listener

I am using the MutationObserver observer to check for elements as they are added with my program. One condition being checked is if the element added is an anchor element (tag=”a”) and then check if the link is a DOI then a contextmenu event listener is attached to it.

This is the code:


const mutationObserverCallback = (mutationList, observer) => {

                var word_regexp = /^10.d{4,9}/[-._;()/:a-zA-Z0-9]+$/
                var word_regexp2 = /^https://doi.org/10.d{4,9}/[-._;()/:a-zA-Z0-9]+$/
                var word_regexp3 = /^DOI: 10.d{4,9}/[-._;()/:a-zA-Z0-9]+$/
                var word_regexp4 = /^DOI: https://doi.org/10.d{4,9}/[-._;()/:a-zA-Z0-9]+$/
    for (const mutation of mutationList) {
        if (mutation.type === "childList") {
            var addedNodes = mutation.addedNodes;
            for (var i = 0; i < addedNodes.length; i++) {
                var addedNode = addedNodes[i]
                var tagName = addedNode.tagName

                if (tagName === "A") {
                    let linkAdress = addedNode.href
                    if (linkAdress.includes("https://doi.org/10.")) {
                        console.log(`link: ${linkAdress}`)
                        console.log("A DOI link was found!")
                        addedNode.addEventListener("contextmenu", doiLinkClicked)
                        doiLinksElementsCollection.push(addedNode)
                    }
                }
            }
        } 
    }
};

This works perfectly well with all the anchor elements that are linked to DOI’s that I have tried except the one on this page. What could be the possible reason for this?

How to set border for each side of a table cell with CKEditor?

I have a table in CKEditor4(Upgrade to CKEditor 5 is possible if that is the only solution) that I need to configure the border for each cell differently. For example some cells might have a border-top and border-bottom while others might need to have a border-left and border-top.

I tried using styles, but you can’t add multiple styles to a table or td in ckeditor. I also tried using the table toolbar plugin, but you can’t configure border to individual sides with it. Does anybody know if it is possible either to add multiple styles or whatever else it may be to be able to configure table cell borders down to each side of the cell?

Javascript Explanation of this keyword with code examples [duplicate]

Could someone please explain to me why ‘this’ correctly works in the second example of setTimeout and not in the first example?

Below logs ‘undefined’

const object = {
  message: 'Hello, World!',

  logMessage() {
    console.log(this.message); // What is logged?
  }
};

setTimeout(object.logMessage, 1000);

Below logs ‘Hello World’

const object = {
  message: 'Hello, World!',

  logMessage() {
    console.log(this.message); // What is logged?
  }
};

setTimeout(() => {
    object.logMessage()
}, 1000);

Also, is the code below logs 4.

var length = 4;

function callback() {
  console.log(this.length); // What is logged?
}

const object = {
  length: 5,
  method(callback) {
    callback();
  }
};

object.method(callback, 1, 2);

This code logs 5

var length = 4;

function callback() {
  console.log(this.length); // What is logged?
}

const object = {
  length: 5,
  method(callback) {
    console.log(this.length);
  }
};

object.method(callback, 1, 2);

Could someone explain the difference please?
I would expect same results and dont understand it.

What is the correct way to use React-Redux when developing a stock dashboard?

I am trying to implement a stock dashboard app which uses the CoinGecko API. At the beginning, I created the following action.js,

export const ALL_COINS = "ALL_COINS";
export const ALL_CATEGORIES = "ALL_CATEGORIES";
export const ALL_EXCHANGES = "ALL_EXCHANGES";
export const ALL_ASSETPLATFORMS = "ALL_ASSETPLATFORMS";

import {
  fetchAllCoins,
  fetchAllCategories,
  fetchAllExchanges,
  fetchAllAssetPlatforms,
} from "../services/coinService";
import {
  ALL_COINS,
  ALL_CATEGORIES,
  ALL_EXCHANGES,
  ALL_ASSETPLATFORMS,
} from "./actionTypes";

export const fetchData = () => async (dispatch) => {
  const response = await fetchAllCoins();
  dispatch({
    type: ALL_COINS,
    payload: response.data,
  });
};

export const fetchCategories = () => async (dispatch) => {
  const response = await fetchAllCategories();
  dispatch({
    type: ALL_CATEGORIES,
    payload: response.data,
  });
};

export const fetchExchanges = () => async (dispatch) => {
  const response = await fetchAllExchanges();
  dispatch({
    type: ALL_EXCHANGES,
    payload: response.data,
  });
};

export const fetchAssetPlatforms = () => async (dispatch) => {
  const response = await fetchAllAssetPlatforms();
  dispatch({
    type: ALL_ASSETPLATFORMS,
    payload: response.data,
  });
};

And the following reducser:

import {
  ALL_COINS,
  ALL_CATEGORIES,
  ALL_EXCHANGES,
  ALL_ASSETPLATFORMS,
} from "./actionTypes";

export const initialState = {
  allCoins: [],
  categories: [],
  exchanges: [],
  assetPlatforms: [],
};

 eslint-disable-next-line no-lone-blocks
 export const fetchReducer = (state = [], action) => {
   switch (action.type) {
     case ALL_COINS:
       return action.payload;
     case ALL_CATEGORIES:
       return action.payload;
     case ALL_EXCHANGES:
       return action.payload;
     case ALL_ASSETPLATFORMS:
       return action.payload;
     default:
       return state;
   }
 }; 
import { configureStore } from "@reduxjs/toolkit";
import { fetchReducer } from "./redusers";
import { combineReducers } from "@reduxjs/toolkit";

const rootReducer = combineReducers({
    fetch: fetchReducer,
  });
  
  export default configureStore({
    reducer: rootReducer,
  });

I also use separate coinService

import axios from "axios";

export const fetchAllCoins = () => {
  return axios.get(
    "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd",
    {
      headers: {
        "Content-Type":
          "application/x-www-form-urlencoded; charset=UTF-8;application/json",
      },
    }
  );
};

export const fetchAllCategories = () => {
  return axios.get("https://api.coingecko.com/api/v3/coins/categories/list", {
      headers: {
        "Content-Type":
          "application/x-www-form-urlencoded; charset=UTF-8;application/json",
      },
    });
};

export const fetchAllExchanges = () => {
  return axios.get("https://api.coingecko.com/api/v3/exchanges", {
      headers: {
        "Content-Type":
          "application/x-www-form-urlencoded; charset=UTF-8;application/json",
      },
    });
};

export const fetchAllAssetPlatforms = () => {
  return axios.get("https://api.coingecko.com/api/v3/asset_platforms", {
      headers: {
        "Content-Type":
          "application/x-www-form-urlencoded; charset=UTF-8;application/json",
      },
    });
};

All of this code above I use in different components, for example:

export default function CustomizedTables() {
  const dispatch = useDispatch();
  const currency = useSelector((state) => state.fetch);
  const input = useInput();
  const [page, setPage] = useState(0);
  const [searchTerm, setSearchTerm] = useState("");
  const [rowsPerPage, setRowsPerPage] = useState(5);

When I used the code which I provided above, I received responses from the API and my UI rendered data. However, I received the same data, so I decided to rewrite my reducer.js like this:

import {
  ALL_COINS,
  ALL_CATEGORIES,
  ALL_EXCHANGES,
  ALL_ASSETPLATFORMS,
} from "./actionTypes";

export const initialState = {
  allCoins: [],
  categories: [],
  exchanges: [],
  assetPlatforms: [],
};

// TODO: finish redusers
export const fetchReducer = (state = initialState, action) => {
  switch (action.type) {

    case ALL_COINS:
      return {
        ...state,
        allCoins: action.payload,
      };

    case ALL_CATEGORIES:
      return {
        ...state,
        categories: action.payload,
      };

    case ALL_EXCHANGES:
      return {
        ...state,
        exchanges: action.payload,
      };

    case ALL_ASSETPLATFORMS:
      return {
        ...state,
        assetPlatforms: action.payload,
      };

    default:
      return state;
  }
};

But for now, this doesn’t work at all. What exactly am I doing wrong? I understand that my mistake is obvious, but I would be grateful for any clues on what direction I should move in order to resolve this issue. Thanks in advance!

But for now, this doesn’t work at all. What exactly am I doing wrong? I understand that my mistake is obvious, but I would be grateful for any clues on what direction I should move in order to resolve this issue. Thanks in advance!

How do I enforce a matcher from jest when using aws-sdk-client-mock-jest?

I have some unit tests where I am using aws-sdk-client-mock-jest to mock DynamoDB operations. I am importing the following packages like so:


import "aws-sdk-client-mock-jest";
const {DynamoDBClient} = require("@aws-sdk/client-dynamodb");
const {QueryCommand} = require("@aws-sdk/lib-dynamodb");
const {mockClient} = require("aws-sdk-client-mock");

In my unit tests, I am using the mocks like this:

const ddbMock = mockClient(DynamoDBClient);

test("Received customer", async () => {
    ddbMock.on(QueryCommand).resolves({
        "name": "customer",
        "data": "some data"
    });
    const db = new DbRepository();

    const customer = await db.getCustomerAsync();
    // some assertions
    expect(customer).toHaveProperty("name", "customer");
});

However, when the toHaveProperty() is called an error is thrown which states: TypeError: this.customTesters is not iterable

What am I doing wrong here?

Any suggestions are welcome. Thanks!

I tried to use the expect library as mentioned here but that does not work.

My unit tests are JS files.

X-Forwarded-For in the request-ip package potential bug

I was reading the request-ip code. (Link here) and I noticed that when dealing with the X-Forwarded-For part it is treated as if it will only be a string always. when in reality it’s very possible that it can be an array of IPs, and when it wants to get client IP from X-Forwarded-For, it assumes that it is just a string of IPs concatenated with a ‘,’ character

I expected it to join the IPs with a ‘,’ character if it was an array, but that’s not the case. what am I doing wrong?