Output of string in function gives an object

I tring to print to string but it’s for some reason gives an object..

// Button
const birthDate = document.querySelector('#dateSubmit');

// Date input
birthDate.onclick = function() {
    let in1 = document.querySelector('#birthday');
    let birthDate = (in1.value).replaceAll("-", "");
    let dateNow = 20220515;
    let old = dateNow - parseInt(birthDate); // 320411
    let result = toString(old);

    console.log(result);  // [object Undefined] ?

    console.log(typeof result);  // string 
}

The react component product which shows the details of the products doesnt render anything

import React , {useContext} from 'react'
import { Button } from "@mui/material";
import Grid from '@mui/material/Grid';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import AddIcon from '@mui/icons-material/Add';
import RemoveIcon from '@mui/icons-material/Remove';
import IconButton from '@material-ui/core/IconButton';
import axios from 'axios'
//import {ids} from "./Scanner"

let ids=[{productid:'9501101530003'}]
const Item = styled(Paper)(({ theme }) => ({
  backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
  ...theme.typography.body2,
  padding: theme.spacing(1),
  textAlign: 'center',
  color: theme.palette.text.secondary,
}));
const Item2 = styled(Paper)(({ theme }) => ({
  backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
  ...theme.typography.body2,
  padding: theme.spacing(2.5),
  textAlign: 'center',
  color: theme.palette.text.secondary,
}));
export default function Cart (){
  console.log(ids)
  let products = []
  
  ids.forEach(element => {
    console.log(element)
    axios.post('http://localhost:4000/app/barcode',element)
    .then((response)=>{
      console.log(response)
      products.push(response.data.product)
      console.log(products)
    })
    });

          function Product ({product}){
            console.log("g")
               console.log(product)
              return(  <Box sx={{ width: '100%' }}>
              <Grid container rowSpacing={1} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
                <Grid item xs={4}>
                  <Item2>{props.product.productName}</Item2>
                </Grid> 
                <Grid item xs={4}>
                  <Item2>2</Item2>
                </Grid>
                <Grid item xs={4} >
                  <Item> 
                     <IconButton color="primary">
                  <AddIcon fontSize='small'/>
                    </IconButton>
                    3
                  <IconButton   color="primary">
                  <RemoveIcon fontSize='small'/>
                    </IconButton>
                  </Item>
                </Grid>
              </Grid>
            </Box>
              )
          }
    return(
        <div >
             <Box sx={{ width: '100%' }}>
              <Grid container rowSpacing={1} columnSpacing={{ xs: 1, sm: 2, md: 3 }}>
                <Grid item xs={4}>
                  <Item>product name</Item>
                </Grid>
                <Grid item xs={4}>
                  <Item>price</Item>
                </Grid>
                <Grid item xs={4}>
                  <Item>
                      quantity
                   </Item>
                </Grid>
              </Grid>
            </Box>
            {products.forEach(element => {
              <Product product={element} />
            })}
            <Box sx={{ width: '100%' }}>
              <Grid container rowSpacing={1} columnSpacing={{ xs: 1, sm: 2, md: 3 }}  justifyContent="center"
                 alignItems="center" >
                <Grid item xs={4}>
                  <Item>total</Item>
                </Grid>
              </Grid>
            </Box>
            <div>
            <Button href='/payment'>pay</Button>
            </div>
        </div>
    )
}      

The requesr using axios returns details of the products . and add that object into the products array. I want render the datails of each and every product using the product component.but the product component doesnt render anything . it dosn’t consolelog the g . please help me
everything else seems to work fine.

i don’t know why this is not working console.log(‘${a}’); [duplicate]

i am learning java script
and i am trying to print the variable value in the console
but in the new way
like below:

let a="hadi",b="jihad",c="zakareya",d="monzer";

console.log(a+" "+b+"n"+c+" "+d);//old way (ES6)

console.log('${a}')//new way

the results:
${a}
which it should give me the value
the first way work fine
but the second way is not working
i don’t know why
please can someone help?

Paste predefined text into an editable textbox by clicking the contextmenu using a browser extension

I’m trying to create a extension for Firefox that inserts a predefined text into the textbox by clicking on an option in the contextmenu.

I wrote the following code but it does not work:

function insert(text) {
document.getElementById('textbox').innerHTML = "THE TEXT I WANT";
}

chrome.contextMenus.create({
title: "TITLE", onclick: insert});

The manifest is also as follows:

"manifest_version": 2,
"name": "NAME",
"description": "DESCRIPTION",
"version": "1",
"author": "ME",
"homepage_url": "https://github.com",

"icons": {
  "48": "icons/48.png",
  "96": "icons/96.png"
},

"permissions": [
  "activeTab",
  "contextMenus",
  "webNavigation"
],

"browser_action": {
  "default_icon": {
  "48": "icons/48.png",
  "96": "icons/96.png"
},
  "default_title": "TITLE"
},

"background": {
  "scripts": [
    "extension.js"
  ]
}

Thanks for your help.

angular compiler syntax issue

I am very new to Angular, as per this link: https://www.npmjs.com/package/@types/correlation-id

I am trying as below, but getting compile error, may I know how to fix below?

import {withId} from 'correlation-id'

 withId.withId(() => {withId.getId();}); //getting compile error here

Uncaught TypeError: Cannot read properties of undefined (reading ‘pathname’) , this error showed while redirecting pages using function

This code is using if-and condition , if a user is signed-in or just signed-up, then he can stay in browse page otherwise he will be send to the sign-in page and etc.

import React from 'react';
import { Route } from 'react-router-dom';
import {Navigate} from "react-router";




export function IsUserRedirect({ user, loggedInPath, children, ...rest }) {
  return (
    <Route
      {...rest}
      render={() => {
        if (!user) {
          return children;
        }

        if (user) {
          return (
            <Navigate
              to={{
                pathname: loggedInPath,
              }}
            />
          );
        }

        return null;
      }}
    />
  );
}

export function ProtectedRoute({ user, children, ...rest }) {
  return (
    <Route
      {...rest}
      render={({ location }) => {
        if (user) {
          return children;
        }

        if (!user) {
          return (
            <Navigate
              to={{
                pathname: 'signin',
                state: { from: location },
              }}
            />
          );
        }

        return null;
      }}
    />
  );
}

Calling the above function:But is showing the errror {Uncaught TypeError: Cannot read properties of undefined (reading ‘pathname’)}

import React from 'react';
import { BrowserRouter, Router, Routes, Route } from 'react-router-dom';
import { Home, Browse } from './pages';
import * as ROUTES from './constants/routes';
import { IsUserRedirect, ProtectedRoute } from './helpers/routes';
import { useAuthListener } from './hooks';
import SignIn from "./pages/signin";
import SignUp from "./pages/signup";

export function App() {
  const { user } = useAuthListener();

  return (
    <Router>
      <Routes>
        <IsUserRedirect user={user} loggedInPath={ROUTES.BROWSE} path={ROUTES.SIGNIN}>
          <SignIn />
        </IsUserRedirect>
        <IsUserRedirect user={user} loggedInPath={ROUTES.BROWSE} path={ROUTES.SIGNUP}>
          <SignUp />
        </IsUserRedirect>
        <ProtectedRoute user={user} path={ROUTES.BROWSE}>
          <Browse />
        </ProtectedRoute>
        <IsUserRedirect user={user} loggedInPath={ROUTES.BROWSE} path={ROUTES.HOME}>
          <Home />
        </IsUserRedirect>
      </Routes>
    </Router>
  );
}

[enter image description here][2]

How do i add the number of guesses into my game? Javascript

I am new to coding and have had alot of help with this project. I have to make a game for a school project. The game is simple, you just have to pick the right cell in the table, what i dont understand is how i would be able to count the number of guesses the player takes. I also have another problem where i so not understand how i would be able to alert the player a direction when they pick the wrong cell, for example if they chose the wrong cell an alert would come up and tell them north or something like that. My code is here if you would like to look at it.

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
 
    <style>
        body {
            text-align: center;
        }
 
        table,
        th,
        td {
            border: 0px solid white;
            border-collapse: collapse;
            width: 45%;
            height: 55px;
            text-align: center;
            vertical-align: center;
            table-layout: fixed;
        }
 
        table.center {
            margin-left: auto;
            margin-right: auto;
        }
 
        .Tableheader {
            border: 0px solid white
        }
 
        .TableCell {
            background-color: rgb(252, 142, 215);
            border: 2px solid black;
        }
 
        .button {
            padding: 5px;
            background-color: #dcdcdc;
            border: 1px solid #666;
            color: #000;
            margin-top: 10px;
        }
 
        button:hover {
            color: yellow;
        }
 
        .TableCell:hover {
            background-color: rgb(255, 230, 0);
        }
        body {
  background-image: url('https://storage.pixteller.com/designs/designs-images/2019-03-27/05/simple-background-backgrounds-passion-simple-1-5c9b95bd34713.png');
}
    </style>
</head>
 
</body>
<div id="MainMenu">
    <form name="form1" action="#" onsubmit="required(event)">
        <ul>
    <h2>Hurkles the Game</h2>
    <p>Type in your name and click start to begin</p>
    <li><input  type='text' name ='text1' id='text1'/></li>
    <li class="rq">*Required Field</li>
        <li><input type="submit" name="submit" id='submit' value="Submit" /></li>
</ul>
</form>
</div>
 <div id="Table">
<div id='playerName'></div>
<h2>Hurkles</h2>
<p> Click a Cell to Find Hurkles</p>
<table>
    <table id="tableID" class="center">
        <tr>
            <td id="R0C0" class="Tableheader"></td>
            <td id="R0C1" class="Tableheader">A</td>
            <td id="R0C2" class="Tableheader">B</td>
            <td id="R0C3" class="Tableheader">C</td>
            <td id="R0C4" class="Tableheader">D</td>
            <td id="R0C5" class="Tableheader">E</td>
            <td id="R0C6" class="Tableheader">F</td>
            <td id="R0C7" class="Tableheader">G</td>
            <td id="R0C8" class="Tableheader">H</td>
            <td id="R0C9" class="Tableheader">I</td>
            <td id="R0C10" class="Tableheader">J</td>
        </tr>
        <tr>
            <td id="R1C0" class="Tableheader">1</td>
            <td id="R1C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R1C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>
        <tr>
            <td id="R2C0" class="Tableheader">2</td>
            <td id="R2C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R2C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>
        <tr>
            <td id="R3C0" class="Tableheader">3</td>
            <td id="R3C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R3C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>
        <tr>
            <td id="R4C0" class="Tableheader">4</td>
            <td id="R4C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R4C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>
        <tr>
            <td id="R5C0" class="Tableheader">5</td>
            <td id="R5C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R5C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>
        <tr>
            <td id="R6C0" class="Tableheader">6</td>
            <td id="R6C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R6C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>
        <tr>
            <td id="R7C0" class="Tableheader">7</td>
            <td id="R7C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R7C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>
        <tr>
            <td id="R8C0" class="Tableheader">8</td>
            <td id="R8C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R8C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>
        <tr>
            <td id="R9C0" class="Tableheader">9</td>
            <td id="R9C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R9C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>
        <tr>
            <td id="R10C0" class="Tableheader">10</td>
            <td id="R10C1" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C2" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C3" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C4" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C5" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C6" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C7" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C8" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C9" class="TableCell" onclick="tableText('red')"></td>
            <td id="R10C10" class="TableCell" onclick="tableText('red')"></td>
        </tr>
        
    </table>
    <br>
    <br>
    <button type="button" id="reset" onclick="hideAll()">Start</button>
</div>
 
<script>
Table.style.display = "none";
MainMenu.style.display = "block";
var name = '';
function Start(){
    Table.style.display = "block"
    MainMenu.style.display = "none"
    document.getElementById('playerName').innerHTML = 'Welcome ' + name;
    
}
var input = document.getElementById("text1");
input.addEventListener("keypress", function(event) {
  if (event.key === "Enter") {
    event.preventDefault();
    document.getElementById("submit").click();
  }
});
   
function tableText(col) {
  if (typeof event !== 'undefined')
    el = event.srcElement
  el.style.backgroundColor = col
}
    
    
    let colIndex = Math.floor(Math.random() * 8) + 1;
    let rowIndex = Math.floor(Math.random() * 8) + 1;
    console.log('col:' + ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'][colIndex-1], 'row:' + rowIndex);
    document.querySelector('#R' + rowIndex + 'C' + colIndex).onclick = () => { 
        tableText('green');
        alert("correct");
    }
    
    function hideAll(){
    Table.style.display = "none"
    MainMenu.style.display = "block"
}
function gameReset(){
}
function required(e){
    e.preventDefault();
    var empt = document.forms["form1"]["text1"].value;
    if(empt == ""){
        alert("Please input your name");
    }
        else{
            name = document.getElementById('text1').value;
            Start()
        }
        
    
}
</script>
 
</html>
</script>

Show Passwords feature in Ultimate Membership pro Forms

How can I add show password field in my forms?
I try this code in my function but didn’t work
add_filter(“um_confirm_user_password_form_edit_field”,”um_user_password_form_edit_field”, 10, 2 );
add_filter(“um_user_password_form_edit_field”,”um_user_password_form_edit_field”, 10, 2 );
function um_user_password_form_edit_field( $output, $set_mode ){

ob_start();
 ?>
<div id='um-field-show-passwords-<?php echo $set_mode;?>' style='text-align:right;display:block;'>
    <i class='um-faicon-eye-slash'></i>
    <a href='#'><?php _e("Show password","ultimate-member"); ?></a>
</div>
<script type='text/javascript'>
    jQuery('div[id="um-field-show-passwords-<?php echo $set_mode;?>"] a').click(function(){ 
     
        var $parent = jQuery(this).parent("div"); 
        var $form = jQuery(".um-<?php echo $set_mode;?> .um-form");

        $parent.find("i").toggleClass(function() {
            if ( jQuery( this ).hasClass( "um-faicon-eye-slash" ) ) {
                $parent.find("a").text('<?php _e("Hide password","ultimate-member"); ?>');
                jQuery( this ).removeClass( "um-faicon-eye-slash" )
                $form.find(".um-field-password").find("input[type=password]").attr("type","text");
               return "um-faicon-eye";
            }
             
            jQuery( this ).removeClass( "um-faicon-eye" );
            $parent.find("a").text('<?php _e("Show password","ultimate-member"); ?>');
            $form.find(".um-field-password").find("input[type=text]").attr("type","password");
          
            return "um-faicon-eye-slash";
        });

        return false; 

    });
</script>
<?php 
return $output.ob_get_clean();

}

Showing an error before uploading an images in Javascript

I have this input file type which accepts only jpg, jpeg, and png mime type. Everything is alright and it shows error if the user submitted a pdf or wordx, I used laravel for that. But the problem is that our prof. wanted to check if the selected files are images and shows an invalid message before the user click the button and can remove that file.

I’ve been searching for two days and I can’t solve it. Is that even possible?

How to load a React component into an Electron child window in a simple way

I am developing an app with Electron and React. Inside the app, I want to open a new window on buttonclick to show a tasklist (Tasklist.js is a component in my src directory). I am able to create and open a new child window with an onClick handler that uses ipcRenderer.send() to trigger the main.js to show the child window. However, I cannot load the page from my Tasklist.js component into the child window. If I do it directly, by inserting the path to Tasklist.js into childWindow.loadUrl(), the childWindow only renders my code inside the Tasklist.js. I have searched around quite a bit and understand that I need to have a DOM element to render the page. Is it somehow possible to render it from my root DOM tree without creating a new DOM element? E.g. something like childWindow.loadURL('index.html#/routeToTasklist')? I tried this (see exact code below) but I get the error “Cannot GET /index.html%23/tasklist”. Is there a way to modify the input into childWindow.loadURL() to make it work? Would very much appreciate any help!

See my main.js code below:

'use strict';

// Import parts of electron to use
const { app, Menu, BrowserWindow, ipcMain} = require('electron');
const path = require('path')
const url = require('url')

const Store = require('./src/components/shared/store/Store');


// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
let childWindow;

// Keep a reference for dev mode
let dev = false;
if (process.defaultApp || /[\/]electron-prebuilt[\/]/.test(process.execPath) || /[\/]electron[\/]/.test(process.execPath)) {
  dev = true;
}

function createWindow() {
  // Create the browser window.
  mainWindow = new BrowserWindow({
    width: 970,
    height: 600,
    show: false,
    resizable: false,
    backgroundColor: '#0C0456',
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true,
      nativeWindowOpen: true
    }
  });


  // and load the index.html of the app.
  let indexPath;

  if (dev && process.argv.indexOf('--noDevServer') === -1) {
    indexPath = url.format({
      protocol: 'http:',
      host: 'localhost:8080',
      pathname: 'index.html',
      slashes: true
    });
  } else {
    indexPath = url.format({
      protocol: 'file:',
      pathname: path.join(__dirname, 'dist', 'index.html'),
      slashes: true
    });
  }

  console.log(indexPath);

  mainWindow.loadURL(indexPath);

  //Remove menu
  Menu.setApplicationMenu(null);

  // Open the DevTools
  mainWindow.webContents.openDevTools({"mode":"detach"});


  // Don't show until we are ready and loaded
  mainWindow.once('ready-to-show', () => {
    mainWindow.show();
  });

  // Emitted when the window is closed.
  mainWindow.on('closed', function () {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });

  mainWindow.webContents.send('fromMain', "hello from main");

}

function openChildWindow(callback){
  childWindow = new BrowserWindow({
    width: 800,
    height: 500,
    parent:mainWindow,
    show:true,
    webPreferences:{
      webSecurity: false,
      nodeIntegration:true
    }
  });

  let childPath;

  if (dev && process.argv.indexOf('--noDevServer') === -1) {
    childPath = url.format({
      protocol: 'http:',
      host: 'localhost:8080',
      pathname: 'index.html#/tasklist',
      slashes: true
    });
  } else {
    childPath = url.format({
      protocol: 'file:',
      pathname: path.join(__dirname, 'dist', 'index.html#/tasklist'),
      slashes: true
    });
  }


  childWindow.loadURL(childPath);


  childWindow.openDevTools();

  childWindow.on('closed', function (){
    childWindow=null;
  });

}

ipcMain.on('openTasklist', event => {
  if(!childWindow){
    openChildWindow();
    childWindow.show();
  }else{
    childWindow.show();
  }
})


// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', function (){
      createWindow();
});

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  // On macOS it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit();
  }
  console.log("app is closed");
});

app.on('activate', () => {
  // On macOS it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (mainWindow === null) {
    createWindow();
  }
});

React Router 6: Retrieving a query string once per page reload

I’m having a need to implement the following behavior in my React application:

  • Whenever a page is loaded (either opened in a browser or refreshed), certain components must retrieve parameters from a query string.
  • React application should be able to modify the query string without reloading a page.
  • Whenever a component retrieving the query string on initial loading / refreshing of a page vanishes but appears again (for example, whenever a tab is switched), it is considered its first render, but it should not provoke additional retrieving of the query string’s parameters.

I have tried:

  • Using useEffect with empty array on target component(-s). Didn’t work well because it was triggering every time I changed a tab (the disappearance of any component is considered its unmount, and its appearance after that is considered a mount, leading to the satisfied condition for a useEffect running on initial render).
  • Using Context API to store the query string in index.js file of an application, and retrieving the context of that query string by target component(-s). Didn’t work due to the same reason: useContext did re-run on re-rendering.

Is there a pattern people use in React with React-Router v6 to achieve this?