react update array of object with checked field in state

const data = [
    {

      id: "1",
      checked: false,
    },
    {
      id: "2",
      checked: false,
    },
    {
      id: "3",
      checked: false,
    },
    {
      id: "4",
      checked: false,
    },
  ];
const [state, setState] = useState(data)

{state.map((item, index) => (
   <div key={index}>
     <input checked={item.checked} type="checkbox" />
     <span>{item}</span>
   </div>
))}

How could I update the checked whenever the checkboxes are tick and untick?

Some examples, but I would like the items checked are to be an array like
[{id: “1”,checked: true,},{id: “2”,checked: true,}];

enter image description here
enter image description here

Alternatives to a large if/switch with multiple cases in JavaScript?

I have multiple if statements (50/60) inside a loop.What would be the best approach to perform this actions, switch or map lookup? How can i implement map lockups for the following examples?

errors.forEach((e) => {
      if (e.field === 'firstName') {
        this.hasErrorFirstName = true;
        this.msgFirstName = e.error;
      }
      if (e.field === 'lastName') {
        this.hasErrorLastName = true;
        this.msgLastName = e.error;
      }
      if (e.field === 'middleName') {
        this.hasErrorMiddleName = true;
        this.msgMiddleName = e.error;
      }
      if (e.field === 'address') {
        this.hasErrorAddress = true;
        this.msgAddress = e.error;
      }
     }

JavaScript String query param breaking because of certain characters [duplicate]

When I send an API request to my backend application I a comment in the url as a query, however whenever a user uses certain characters like: #,& or % the url query breaks of at these characters.

Currently I have implemented this replaceAll functions to temporary change these characters and transform them back on the backend.

&comment=${candidate.comment
          .replaceAll("&", "*-and-*")
          .replaceAll("#", "*-hash-*")
          .replaceAll("%", " procent")
          .replaceAll("n", "*line-break*")}

However this seems like an hassel to keep changing these characters.

Is there a proper way to handle the issue of using these characters in a query param?

Dismiss error when variable is undefned javascript

When I run this code

return (
          val.ticket.ticketNumber.toLowerCase().includes(inputText) ||
          val.ticket.source.toLowerCase().includes(inputText) ||
          val.ticket.lagoonMaterial.toLowerCase().includes(inputText) ||
          val.ticket.vendor.toLowerCase().includes(inputText) ||
          val.ticket.gallons.toLowerCase().includes(inputText);
        );

Sometimes one the properties is missing and that gives me this error

TypeError: undefined is not an object (evaluating
‘val.ticket.vendor.toLowerCase’)

How can I dismiss this property without having to use if statement?

Undefined array in cookie

I have a javascript file that calls the function and set the cookie whenever i clicked the table, it set the table cell data in cookie which i used to in naming the uploaded picture in another php file. I created another file to edit data in modal but when i get the cookie, an undefined array is what i get but no error for the other cookie which was set in the same js function call. In browser i can see the cookie and its value. I created php file to show the cookie and no problem at all.

Javascript file

function setCookie(cname,cvalue,exdays) {
  const d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  let expires = "expires=" + d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + "; path=/";
}

function myCellValue(x,y=0) {

  oldnum = document.getElementById("tblbidding").rows[x].cells[7].innerHTML;
  $bidcode = document.getElementById("tblbidding").rows[x].cells[y].innerHTML;
  var Myelement = document.getElementById("bidcode");
  Myelement.value = $bidcode;

  // Some other code here (long codes to display)

  setCookie("bidcode", $bidcode, 1);
  setCookie("tbl-x",x,1);
  setCookie("oldnum",oldnum,1);
} ``` 

PHP page used to show the cookie

<!DOCTYPE html>
<?php
$cookie_name1 = "bidcode";
?>
<html>
<body>

<?php
if(!isset($_COOKIE[$cookie_name1])) {
     echo "Cookie named '" . $cookie_name1 . "' is not set!"; echo '<br>';
} else {
     echo "Cookie '" . $cookie_name1 . "' is set!<br>";
     echo "Value is: " . $_COOKIE[$cookie_name1]; echo '<br>';
}
?>

<p><strong>Note:</strong> You might have to reload the page to see the value of the cookie.</p>

</body>
</html>

I have a screenshot when i tried to dump and print_r the cookie, the cookie in browser and the php page showing the cookie and its value

I’m still a newbie in web programming.enter image description here

update let value onclick

I’m trying to update a boolean value onclick without any luck.

const myDropdownMenu = document.getElementById("dropdownMenu");
const openNav = document.getElementById("openNav");
const closeNav = document.getElementById("closeNav");

let mobileMenu = false;

function toggleMenu() {
  mobileMenu = !mobileMenu;
}

if (mobileMenu) {
  myDropdownMenu.style.display = "flex";
  closeNav.style.display = "flex";
  openNav.style.display = "none";
} else {
  myDropdownMenu.style.display = "none";
  openNav.style.display = "flex";
  closeNav.style.display = "none";
}
      <div>
        <a href="index.html"> <h1>CAVVD</h1> </a>
        <div id="mobileNav" class="mobileNavigation">
          <button id="openNav" onclick="toggleMenu();">
            Open
          </button>
          <button id="closeNav" onclick="toggleMenu();">
            Close
          </button>
          <div id="dropdownMenu">
            <a href="index.html#sobreNosotros">Sobre Nosotros</a>
            <a href="index.html#reuniones">Reuniones</a>
            <a href="ForodeConsultas.html">Foro de Consultas</a>
            <a href="index.html#HaceteVoluntario">Hacete Voluntario</a>
            <a href="Fotos.html">Fotos</a>
            <a href="index.html#contacto">Contacto</a>
            <a class="Dona" a href="index.html#Dona!"> DonĂ¡!</a>
          </div>
        </div>
      </div>

Everything is working except the let mobileMenu, that is not updating with the toggleMenu() function. But if I return a simple console.log or alert, it works.

Can anybody help me? thanks

What does it matter if there are many nodejs emitter listeners?

I’m writing a TCP server application using NodeJS. However, each socket runs on a separate process. To send messages to specific clients, I used Emitter, and each socket generates its own listener. So if there are 10000 connected devices, the application will create 10000 listeners. This looks terrible. What dangers will this pose? I can’t find a solution to send a message from one client to another in the TCP protocol writing NodeJS code. Thanks for all the help. Have a nice working day.

Read codebase of javascript function

I just realize that I can use the function console.log to read a codebase of any javascript function. Anyone how it happens? and what behind the sense of this action (read codebase)
Example:
Open chrome console and paste this code

function superMan(){
    var i=i+1;
    var j=i+1;
}

then you use the function console.log like console.log(superMan) and you can see the codebase of SuperMan
enter image description here

How can we use style prop in TouchableWithoutFeedback or TouchableWithNativeFeedback?

I want to give some style to the TouchableWithNativeFeedback , The style prop doesnot work although it works fine with the TouchableOpacity but it wont work with the native feedback. Is there any way we can make it work. I found a solution but I dont want to do it is there any other way.

The solution that I found in github.

link :

https://github.com/facebook/react-native/issues/8307

Answer:

I was having the same issue. But I wrapped the
TouchableWithoutFeedback element with a view and styled the view
instead. And I wrapped everything inside the TouchableWithoutFeedback
with another view with a style identical to the parent view. This
seems to have fixed it for me.

Thank you.

react z-index css button value not working

I am trying to design a responsive website with react using no bootstrap or other plugins, just css/js/html. So far my responsive layout works but a button

{/* Open & Close Sidebar Button */}
                    <button className="sidebarBtn" onClick={sideNavClicked}>
                        <a className={`chevron-char ${toggleSidebarIcon ? 'sidebar-collapsed' : ' '} `} >&gt;</a>
                    </button>

Appears behind the sidebar when I want it infront
enter image description here

I’ve tried setting and specifying the z-index value for all import elements but no luck, can anyone give advice how to solve this in react

my component file Mainsidebar.js and MainSidebar.css:

import React from 'react'
import "./MainSidebar.css"
import ProgressiveImage from "./ProgressiveImage";
import { Link, useNavigate } from "react-router-dom";
const MainSidebar = ({ children }) => {

    function getRandomImage() {

    }

    //toggle open/close sidenav depending on current status
    function sideNavClicked() {
        console.log('sideNavClicked()')
        setShowSideNav(!showSideNav)
        setToggleSidebarIcon(!toggleSidebarIcon)

    }

    function menuItemClicked() {
        console.log('toggleMenuItem()')
        setToggleMenuItem(!toggleMenuItem)
    }

    const [showSideNav, setShowSideNav] = React.useState(true);
    const [toggleMenuItem, setToggleMenuItem] = React.useState(true);
    const [toggleSidebarIcon, setToggleSidebarIcon] = React.useState(false);

    return (
        <>
            <div className="main-content">
                {/* Sidebar */}
                <div id="mySidebar" className={` super-animation sidebar ${showSideNav ? 'sidebar-show' : ' '} `} >
                    {/* Martin Barker */}
                    <div className="color0">
                        {/* Name Text */}
                        <a href="#" className='sidebar-header color1'>Martin Barker</a>
                    </div>

                    <a href="#" className='color2'>About</a>

                    <a className="color3" data-ulid="expand_this" onClick={menuItemClicked} href="#">Projects X</a>
                    <ul className={` ${toggleMenuItem ? 'ul-show' : ' '} `}>
                        <li><a href="#">tagger.site</a></li>
                        <li>
                            <Link to="/rendertune">RenderTune</Link>
                        </li>
                        <li><a href="#">Vinyl2Digital</a></li>
                        <li><a href="#">Popularify</a></li>
                    </ul>
                    <a href="#">Blog</a>
                    <a href="#">Contact</a>

                    {/* Image Display LazyLoad */}
                    <div className='imgColor'>
                        <button >Refresh Colors</button>
                        <br></br>
                        <ProgressiveImage
                            className={"colorSrcImg"}
                            alt={"color source image"}
                            overlaySrc={
                                require("../aesthetic-images/thumbnails/418112_thumb.jpg")
                            }
                            src={
                                require("../aesthetic-images/418112.jpg")
                            }
                        />

                    </div>
                </div>

                {/* Page Contents */}
                <div id="main" className={` super-animation ${showSideNav ? 'show-sidebar' : ' '} `}>

                    {/* Open & Close Sidebar Button */}
                    <button className="sidebarBtn" onClick={sideNavClicked}>
                        <a className={`chevron-char ${toggleSidebarIcon ? 'sidebar-collapsed' : ' '} `} >&gt;</a>
                    </button>

                    <div>
                        <h1>responsive page content responsive page content responsive page content </h1>
                        <br></br>
                        <h4>responsive page content </h4>
                    </div>

                    {/* 
                    <div className={`  ${!toggleSidebarIcon ? ' ' : '  '}`}>
                        {children}
                    </div>
                    */}

                </div>
            </div>
        </>
    )
}

export default MainSidebar
.colorSrcImg{
    width:100px
}

.sidebar-txt{
    font-size: 7px;

}

html,
body {
  font-family: "Lato", sans-serif;
  height: 100%;
  margin: 0;
}

.super-animation{
  -webkit-transition: -webkit-transform 300ms ease;
  -webkit-transition-duration: 300ms;
  -moz-transition: -moz-transform 300ms ease;
  transition: transform 300ms ease;
}

.main-content{
  margin: 0;
  display: flex;
  position: relative;
  width: 100%;
  height: 100%;
}

.sidebar {
  height: 100%;
  width: 200px;
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: #111;
  overflow-x: hidden;
  
  right: 0;
  -webkit-transform: translate3d(calc(-100%), 0, 0);
  -moz-transform: translate3d(calc(-100%), 0, 0);
  transform: translate3d(calc(-100%), 0, 0);
}

.sidebar.sidebar-show{
  -webkit-transform: translate3d(0, 0, 0);
  -moz-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
}

.sidebar a {
  padding: 8px 8px 8px 32px;
  text-decoration: none;
  font-size: 19px;
  color: #818181;
  display: block;
  transition: 0.3s;
}

.sidebar a:hover {
  color: #f1f1f1;
}

.chevron-char{
  height:22px;
  color:white;
}


.sidebar-collapsed {
  transform: rotate(180deg);
  transition: all 0.25s ease-in-out;
  display:inline-block;
}

.sidebar .closebtn {
  position: absolute;
  top: 0;
  right: 25px;
  font-size: 36px;
  margin-left: 50px;
}

.sidebarBtn {
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;

  padding: 10px 15px;
  margin-left: -40px;
  border: none;

  background-color: pink;
  color: yellow;


  z-index:100!important;

  box-shadow: 0px 1px 4px 1px rgb(0 0 0 / 30%);
  cursor: pointer;
}

.sidebarBtn:hover {
  background-color: #444;
}

#main {
    padding-left: 16px;
    z-index:9999!important;
}

#main.show-sidebar{
  -webkit-transform: translate3d(200px, 0, 0);
  -moz-transform: translate3d(200px, 0, 0);
  transform: translate3d(200px, 0, 0);
  margin-right: 190px;
  min-width: 15px;
  overflow: overlay;
}

.main-content .sidebar ul{
  margin: 0;
  max-height: 0px;
  overflow: hidden;
  transition: max-height 200ms ;
}

.main-content .sidebar ul.ul-show{
  transition: max-height 200ms ease-in;
  max-height: 400px;
}

/* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */
@media screen and (max-height: 450px) {
  .sidebar {padding-top: 15px;}
  .sidebar a {font-size: 18px;}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

Different sequenece of number from array of numbers

I want to have an array of numbers and I want to get the different sequences from the same array of numbers. E.g of an array is : [ [ 7, 3 ], [ 7, 5, 3, 2 ], [ 7, 5 ], [ 7 ] ]
I want to have different and multiple sequences. I have been trying hard on this for 2 days now and couldn’t get it.

Wanted to remove and add active to className in reactJS

I have made this work in javascript, but someone pointed that I am getting the .navlist just once and React probably hasn’t rendered the DOM at this point.

import React from "react";
import './navbar.css'

import { FaHome, FaLightbulb, FaGhost, FaEnvelope, FaSalesforce, FaLinkedin, FaMoon } from "react-icons/fa";

const Navbar = () => {
    return (
        <div className = "navbar">
            <ul>
                <li className= "navlist active">
                    <a href = "#home">
                        <FaHome size={ 25 } className="icons"/>
                        <span class = "text">Home</span>
                    </a>
                </li>
                <li className = "navlist">
                    <a href = "#aboutme">
                        <FaGhost size={ 25 } className="icons"/>
                        <span class = "text">About Me</span>
                    </a>
                </li>
                <li className = "navlist">
                    <a href = "#projects">
                        <FaLightbulb size={ 25 } className="icons"/>
                        <span class = "text">Projects</span>
                    </a>
                </li>
                <li className = "navlist">
                    <a href = "#contactme">
                        <FaEnvelope size={ 25 } className="icons"/>
                        <span class = "text">Contact me</span>
                    </a>
                </li>
                <li className = "navlist">
                    <a href = "https://www.linkedin.com" target="_blank" rel="noreferrer">
                        <FaLinkedin size={ 25 } className="icons"/>
                        <span class = "text">linked In</span>
                    </a>
                </li>
                <li className = "navlist">
                    <a href = "https://trailblazer.me" target="_blank" rel="noreferrer">
                        <FaSalesforce size={ 29 } className="icons"/>
                        <span class = "text">Salesforce</span>
                    </a>
                </li>
                <li className = "navlist">
                    <a href = "#darkmode">
                        <FaMoon size={ 25 } className="icons"/>
                        <span class = "text">On/Off</span>
                    </a>
                </li>
                <div className="indicator"></div>
            </ul>
        </div>
    )
}

const list = document.querySelectorAll('.navlist');
function activeLink(){
    list.forEach((item) =>
    item.classList.remove('active'));
    this.classList.add('active');
}
list.forEach((item) => 
item.addEventListener('click', activeLink));

export default Navbar

I don’t know much about react as I have just started but how could the last bit of code be converted to reactJS? It was also pointed out that it could be done by using onClick?

Retrieving FeatureTable and FeatureLayer information

I am having issues retrieving the values from my featureTable and featureLayer. Is there any solution to pass the values into the functions defined outside of this? For example I am trying to retrieve the values and pass them into the cancelUserEditRecords function. The cancelUserEditRecords would be undefined when using onClick thus I have to place it outside the scope.

    require([
      "esri/layers/FeatureLayer",
      "esri/dijit/FeatureTable",
      "dojo/dom",
      "dojo/parser",
      "dojo/ready",
      "dojo/on",
      "dijit/layout/ContentPane",
      "dijit/layout/BorderContainer",
      "app/context/app-config"
    ], function (
      FeatureLayer, FeatureTable, dom, parser, ready, on, ContentPane, BorderContainer, AppConfig
    ) {
      var queryObject = this._parseParameters();
      if (queryObject.token) {
        portalToken = queryObject.token;
      }
      parser.parse();
      ready(function () {
        // editable FeatureLayer
        let url = AppConfig.baseRestURLHosted + AppConfig.announcementTable;
        if (portalToken) {
          if (typeof url === "string") {
            if (url.indexOf("?") === -1) url += "?";
            else url += "&";
            url += "token=" + encodeURIComponent(portalToken);
          } else {
            url.token = portalToken;
          }
        }
        var featureLayer = new FeatureLayer(
          url, {
            mode: FeatureLayer.MODE_ONDEMAND,
            outFields: ["announcement", "created_user", "created_date", "last_edited_user",
              "last_edited_date",
              "status"
            ],
            visible: true,
            editable: true,
            id: "fLayer2"
          });
        var featureTable = new FeatureTable({
          featureLayer: featureLayer,
          editable: false,
          syncSelection: true,
          dateOptions: {
            datePattern: 'dd/MM/y',
            timeEnabled: true,
            timePattern: 'HH:mm:ss',
          },
          hiddenFields: ["objectid", "objectid_1"],
          fieldInfos: [{
              name: 'announcement',
              alias: 'Announcement'
            },
            {
              name: 'created_user',
              alias: 'Created By',
            },
            {
              name: 'created_date',
              alias: 'Created Date',
            },
            {
              name: 'last_edited_user',
              alias: 'Modified By',
            },
            {
              name: 'last_edited_date',
              alias: 'Modified Date',
            },
            {
              name: 'status',
              alias: 'Status',
            }
          ],
          gridOptions: {
            noDataMessage: "No Data",
            allowSelectAll: true,
            cellNavigation: true,
            selectionMode: "extended",
            pagination: true,
            allowTextSelection: true,
            pageSizeOptions: [10, 25, 50, 100, 200],
            columnHider: true,
            columnResizer: true,
            pagingDelay: 300
          },
          menuFunctions: [{
              label: "Add New Record",
              callback: addNewRecord
            },
            {
              label: "Delete Record(s)",
              callback: deleteRecord
            },
            {
              label: "TEST",
              callback: editAnn
            }
          ]
        }, 'tableNode');
        featureTable.startup();
             
        function editAnn(){
          console.log("Editing")
          console.log(featureTable)
          require(["app"], function () {
            require(["app/context/AppClient", "dojo/_base/lang"],
              function (AppClient, lang) {
                var self = this;
                if (featureTable.selectedRows.length === 0) {
                  //var announcement = featureTable.selectedRows[0].announcement;
                  var approvalForm = document.getElementById("approvalForm");
                  approvalForm.style.display = "block";
                  var announcementInput = document.getElementById('announcementInput').value
                  if (announcementInput.length === 0){
                    document.getElementById("editError").innerHTML = "Please add an announcement";
                    featureTable.refresh()
                  }
                }
                else if (featureTable.selectedRows.length > 0) {
                  alert("Please select only one record.");
                }
                else {
                  alert("Please select a record.");
                }
              }
            );
          });
        }
        function addNewRecord(evt) {
                featureLayer.applyEdits(
                  [{
                    'attributes': 'announcement'
                  }],
                  null,
                  null,
                );    
        }
        function deleteRecord(evt) {
                if (featureTable.selectedRows.length > 0) {
                  var objectIds = "";
                  for (var i = 0; i < featureTable.selectedRows.length; i++) {
                    objectIds += featureTable.selectedRows[i].objectid + ", ";
                  }
                  objectIds = objectIds.substring(0, objectIds.length - 2);
                } else {
                  alert("Please select at least one record.");
                }
          }
      });
    });
    function cancelEditUserRecord() {
        var approvalForm = document.getElementById("approvalForm");
        approvalForm.style.display = "none";
        console.log(featureLayer)
        console.log(featureTable)
    }      
    function submitRecord(){
      require(["app"], function () {
        require(["app/context/AppClient", "dojo/_base/lang", "dojo/request/xhr", "dojo/i18n!app/nls/resources"],
        function (AppClient, lang, dojoRequest, i18n) {
          document.getElementById("announcementError").innerHTML = "";
          var announcementInput = document.getElementById('announcementInput').value;
          console.log(announcementInput)
          var regex = new RegExp(/[~`!#$%^&*+=-[]\';,/{}|\":<>?]/);
          function regexTest(value){
            if(regex.test(value)){
              return true
                    }
            else{
              return false;
                    }
                  }
          var validation = 0;
          if (announcementInput.length == 0) {
              validation++;
              document.getElementById("editError").innerHTML = "Reason is mandatory.";
              var announcement = featureTable.selectedRows[0].announcement;
            }
            if(validation == 0){
                featureLayer.applyEdits(
                  [null,
                  {
                    'attributes': 'announcement'
                  }],
                  null,
                  function (results) {
                    var client = new AppClient();
                    client.createAuditTrailForTable(i18n.auditTrailType.addAnnouncement, "", "", "",
                      portalToken);
                    featureTable.refresh();
                  },
                  function (err) {
                    console.log(err);
                  }
                );
            }
          }
        )}
      )
    }
    function _parseParameters() {
      var query = window.location.search;
      if (query.indexOf('?') > -1) {
        query = query.substr(1);
      }
      var pairs = query.split('&');
      var queryObject = {};
      for (var i = 0; i < pairs.length; i++) {
        var splits = decodeURIComponent(pairs[i]).split('=');
        var parameterValue = "";
        // loop parameter values in array elements since value may contain '='
        for (var j = 1; j < splits.length; j++) {
          if (parameterValue.length > 0) {
            parameterValue += "=";
          }
          parameterValue += splits[j];
        }
        queryObject[splits[0]] = parameterValue;
      }
      return queryObject;
    }
   
 
  </script>
</head>
<body>
  <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters: false"
    style="width:100%; height:100%;">
    <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center', splitter:true" style="height:50%;">
      <div id="tableNode"></div>
    </div>
  </div>
  <div id="approvalForm" style="display: none; padding:15px">
    <div class="row">
      <div class="col-xs-12">
        <div id="content" class="row">
          <div class="col-xs-4">
            <h2>Announcement</h2>
          </div>
          <div class="col-xs-8">
            <input type="text" class="form-control" id="announcementInput" name="announcement" data-dojo-attach-point="announcement">
          </div>
          <p id="announcementError" class="g-metadata-validation-errors text-danger"></p>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-xs-12">
        <div id="content" class="row">
          <div class="col-xs-12">
            <button id="submitButton" class="btn btn-sm btn-primary" type="submit" onclick="submitRecord()">Edit</button>
            <button class="btn btn-link btn-sm" type="submit" onclick="cancelEditUserRecord()">Cancel</button>
            <span class="pull-left g-loading" id="loadingIndicator" style="display: none;"></span>
            <p id="editError" class="g-metadata-validation-errors text-danger" style="display: inline-block;"></p>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

How do I make a use effect run before another while using an API in react.js

The purpose of this project is to dynamically get the coordinates and bounds from a map API and use its values to get the data of places attached to that area

The situation I have is that on my app.js I have two use effects:

  • the first is to get the user’s location after the window is loaded this makes it possible for the map API to work.

  • the second is to get the data from a different API based on the bounds
    gotten from the map.

    const App =() => {
    const [places, setPlaces]= useState([]);
    const [coordinates, setCoordinates] = useState({lat: 0, lng: 0});
    const [bounds, setBounds]= useState(null);

         useEffect(()=>{
             let mounted = true;
             window.addEventListener('load', (event) => { 
             navigator.geolocation.getCurrentPosition(({ coords: {latitude, longitude} }) => {
                 if (mounted){
                 setCoordinates({ lat: latitude, lng: longitude });
                 }
             },(err)=> {
                 console.warn(`ERROR(${err.code}): ${err.message}`);
               },{maximumAge:60000, timeout:5000, enableHighAccuracy:true});
               console.log('page is fully loaded');
             });
             return ()=>{
                 mounted = false;
             }
         }, []);
    
         useEffect(() => {
    
             console.log(coordinates, bounds); 
             let isApiSuscribed= true;
             getPlacesData(bounds.sw, bounds.ne)//I am trying to get the API data using this
              .then((data) => {
    
                  if (isApiSuscribed){
                  console.log(data);
    
                  setPlaces(data);
                  }
              });
              return ()=>{
                  isApiSuscribed=false;
              }
         }, [coordinates,bounds]);
    
         return(
             <>
                 <CssBaseline />
                 <Header />
                 <Grid container spacing={3} style={{width:'100%'}}>
                     <Grid item xs={12} md={4}>
                         <List places={places}/>
                     </Grid>
                     <Grid item xs={12} md={8}>
                         <Map
                             setCoordinates={setCoordinates}
                             setBounds = {setBounds}
                             coordinates ={coordinates}
                         />
                     </Grid>
                 </Grid>
             </>
         )
     }
     export default App;
    

The Challenge is that if I do not call the bounds.sw, bounds.ne parameters in the getPlacesData() function my Locally hosted page would run showing the appropriate Map and other components but the data that I need to fetch from the other API would not work.

And when I then call the bounds.sw, bounds.ne parameters in the getPlacesData() function then nothing is rendered on the screen and I get the following error codes:
Error Message

this is the code for the API that is to return the data back

import axios from 'axios';

const URL ='https://travel-advisor.p.rapidapi.com/restaurants/list-in-boundary';



export const getPlacesData = async (sw, ne) => {
  try {
    const { data: { data } } = await axios.get(URL, {
      params: {
        bl_latitude: sw.lat,
        bl_longitude: sw.lng,
        tr_longitude: ne.lng,
        tr_latitude: ne.lat,
      },
      headers: {
        'x-rapidapi-key': process.env.REACT_APP_RAPID_API_TRAVEL_API_KEY,
        'x-rapidapi-host': 'travel-advisor.p.rapidapi.com',
      },
    });

    return data;
  } catch (error) {
    console.log(error);
  }
};

Please what do I do?