Using useState variable outside the function in reactJs

i have a function, in which i am using a useState hook on a variable named active. This variable takes a string value, and on click it takes the value of the category which is clicked on. My goal is to use this value of category outside the function in order to perform operations on that particular category.

Is there a way in which i can export the value which this active useState variable has, outside this function anywhere in the project.

the structure of my code is as follows:

export const funct = () => {

  // useState variable that will take the value of category that it gets clicked on/
  const [active, setActive] = useState('');


  return (
    <div className='abc'>
      {
        content.map((info) =>

           // Card is the category card which has a string value associated with, i.e. (info.name)

          <Card key={info.name} cardInfo={info} state={active} onClick={() => setActiveState(info.name)} />)

      }
    </div>
  )
}

any help would be appreciated. thank you

How to track each time a new setInterval on an array of elements arriving from the API?

  1. I receive data from the API, and I save only objects with status 1 or 2 to the state.

`const [items, setItems] = useState([]);

      const handleOnFetchData = useCallback((data) => {
        setItems(
          data.results.filter(
            (report) => report.status === 1 || report.status === 2
          )
        );
      }, []);`
  1. Objects change their status over time. And you need to track it every 5 seconds in the interval.

How I do:

  1. There is a useEffect that depends on the state with items, and if the state is not empty, then iterates over the state and calls the monitoringItem function for each element

`let interval;

  useEffect(() => {
    if (items.length > 0) {
      items.forEach((report, i) => {
        interval = setInterval(() => {
          monitoringItem(report.record_id);
        }, 5000);
      });
    } else {
      clearInterval(interval);
    }
  }, [items]);`
  1. the monitoringItem function sends a request every 5 seconds and checks the status of the item. if the status is anything other than 1 or 2, then stop the interval and remove that item from the state.

    const monitoringItem = useCallback(
          async (id) => {
            const response = await API.get(`/reports/${id}`);
    
            const monitoredReport = response.data.results[0];
    
            if (monitoredReport.status !== 2 && monitoredReport.status !== 1) {
              clearInterval(interval);
              setItems(
                items.filter((rep) => rep.record_id !== monitoredReport.record_id)
              );
            }
          },
          [items]
        );
    

**
Question and problem**: How can I hang my own setInterval for each item when adding. Now everything is fine with 1 item. but adding others breaks everything.

React : Checkbox stuck to true, but state is updated

I’ve a value in my state to store a list of cities, a checkbox to select them in a table, and an event listener to add the selected value to the state.

I can toggle the checkbox one time, from false to true. Then, it can’t toggle to false. I’m logging the state and it’s correctly updated, so I don’t understand why my checkbox isn’t updated.

For example :

  • The “New York” check box isn’t checked, so state is []
  • I can check it, the state changes to ["New York"]
  • When I uncheck it, the state changes to [], but nothing happens in the checkbox

Here’s the code :

const [selected, setSelected] = useState([]);
<input type="checkbox" onChange={(e) => handleRowSelect(e, bpf.city_name)} checked={selected.indexOf(bpf.city_name) > -1} />
const handleRowSelect = (e, city) => {
        let arr = selected;
        const index = arr.indexOf(city)
        if (index === -1) {
            arr.push(city);
        } else {
            arr.splice(index, 1);
        }
        setSelected(arr);
        console.log(arr)
        console.log(selected)
        dispatch({ type: 'SET_SEL_BPF', payload: selected })
    }

Hooks can only be called inside of the body of a function component. Error: Invalid hook call

I’m trying to implement a shopping cart in my app. I created another file that has the functions I want to be called I keep getting an invalid hook call.

export function CartProvider(props) {
      const [items, setItems] = useState([]);
    
    function addItemToCart() {
        console.log("test")
    }

  return (
    <CartContext.Provider 
      value={{items, setItems, getItemsCount, addItemToCart, getTotalPrice}}>
      {props.children}
    </CartContext.Provider>
  );
}

There is more code in the file but I’ve narrowed the issue down to this, but as soon as I import the CartContext and make it a const I get the issue.

import {CartContext} from '../CartContext'
const {addItemToCart} = useContext(CartContext)

export default class ProductCard extends Component {


constructor(props) {
    super(props)
    this.state = {
        name: this.props.postname,
        price: this.props.postprice,
        image: this.props.postimage,
        description: this.props.postDescription,
        quantity: this.props.postquantity,
        
    }
    
}

How to store an image in the database?

hello I’m creating a profile screen and I would like users to upload their avatar… but I have no idea how to store this in the bank… api in java using postgres, I just wanted some direction what to look for to do right.

my site receive the image and store it in the database

Element sort in javascript

I want to sort elements in a page using javascript.
In the page we have elements that are repeating but the content is differen (Just the inner text) in kg-toggle-heading-text and kg-toggle-content. We would like to sort element blocks that have class kg-card kg-toggle-card by the content of kg-toggle-heading-text alphabetically options to sor differently are not needed. The site is made on ghost.io platform and doesnt support sorting out of the box so i need to add the sorting via HTML embed.
Could this be done.

snippet of code

<div class="single-content gh-content kg-canvas">
   <div class="kg-card kg-toggle-card" data-kg-toggle-state="close">
      <div class="kg-toggle-heading">
         <h4 class="kg-toggle-heading-text">Klēpjdators</h4>
         <button class="kg-toggle-card-icon">
            <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
               <path class="cls-1" d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"/>
            </svg>
         </button>
      </div>
      <div class="kg-toggle-content">
         <p>ir mazs līdznēsājams <a href="https://lv.wikipedia.org/wiki/Person%C4%81lais_dators">personālais dators</a>, kas parasti sver 1-6 kilogramus, atkarībā no izmēra, materiāliem un citiem faktoriem.</p>
         <br>
      </div>
   </div>
   <div class="kg-card kg-toggle-card" data-kg-toggle-state="close">
      <div class="kg-toggle-heading">
         <h4 class="kg-toggle-heading-text">Personālais dators</h4>
         <button class="kg-toggle-card-icon">
            <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
               <path class="cls-1" d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"/>
            </svg>
         </button>
      </div>
      <div class="kg-toggle-content">
         <p>ir jebkurš dators, kura cena, izmērs un veiktspēja ir pielāgota individuālai lietošanai un ir paredzēta speciāli gala patērētājam, kurš ar šo iekārtu var darboties patstāvīgi un neatkarīgi.</p>
      </div>
   </div>
   <div class="kg-card kg-toggle-card" data-kg-toggle-state="close">
      <div class="kg-toggle-heading">
         <h4 class="kg-toggle-heading-text">Klaviatūra</h4>
         <button class="kg-toggle-card-icon">
            <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
               <path class="cls-1" d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"/>
            </svg>
         </button>
      </div>
      <div class="kg-toggle-content">
         <p>jeb <b>datora klaviatūra</b> ir datora ievades iekārta. Standarta datora tastatūrai ir 101 vai 104 taustiņi. Datora tastatūrai (ierasti <a href="https://lv.wikipedia.org/wiki/QWERTY">QWERTY</a> tipa) ir vairāk kā simt taustiņu, turklāt taustiņu nozīme nav pastāvīga.</p>
      </div>
   </div>
   <div class="kg-card kg-toggle-card" data-kg-toggle-state="close">
      <div class="kg-toggle-heading">
         <h4 class="kg-toggle-heading-text">Datorpele</h4>
         <button class="kg-toggle-card-icon">
            <svg id="Regular" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
               <path class="cls-1" d="M23.25,7.311,12.53,18.03a.749.749,0,0,1-1.06,0L.75,7.311"/>
            </svg>
         </button>
      </div>
      <div class="kg-toggle-content">
         <p>ir <a href="https://lv.wikipedia.org/wiki/Ier%C4%ABce">ierīce</a> kursora pārvietošanai pa datora ekrānu. Tās funkcijas ir atkarīgas no konkrētās programmas, ar kuru strādā <a href="https://lv.wikipedia.org/w/index.php?title=Lietot%C4%81js&amp;action=edit&amp;redlink=1">lietotājs</a>. Lielākajā daļā programmu peles pārvietošana izraisa noteiktas formas veidojuma (<a href="https://lv.wikipedia.org/wiki/Kursors">kursora</a>) — pārvietošanos pa ekrānu.</p>
      </div>
   </div>
   <figure class="kg-card kg-bookmark-card">
      <a class="kg-bookmark-container" href="https://dainas-saite.ghost.io/glosarijs/">
         <div class="kg-bookmark-content">
            <div class="kg-bookmark-title">Glosārijs</div>
            <div class="kg-bookmark-description">Klēpjdatorsir mazs līdznēsājams personālais dators, kas parasti sver 1-6 kilogramus, atkarībā no izmēra, materiāliem un citiem faktoriem. Personālais datorsir jebkurš dators, kura cena, izmērs un veiktspēja ir pielāgota individuālai lietošanai un ir paredzēta speciāli gala patērētājam, kurš ar šo i…</div>
            <div class="kg-bookmark-metadata"><img class="kg-bookmark-icon" src="https://dainas-saite.ghost.io/favicon.ico" alt=""><span class="kg-bookmark-author">dainas-saite</span><span class="kg-bookmark-publisher">Arturs Rasnacis</span></div>
         </div>
         <div class="kg-bookmark-thumbnail"><img src="https://static.ghost.org/v4.0.0/images/publication-cover.jpg" alt=""></div>
      </a>
   </figure>
</div>

The elements on the page. The sortable elements are these toggle cards and they should be sorted alphabetically. The sort needs to be preformed because elements are added one by one and ghost io platform coesnt use CMS system basis is you get what you see.

enter image description here

How to execute node command when some event occur in electron js window

I am making a electron js application which have two buttons.
I have assigned click event listners on both of them.
What I want to do uppon someone click them is to increase or decrease brightness respectively.

I have build a function in node.js that does increase the brighthness if we run using sudo command.

Here is the function:

let fs = require("fs");

function inc() {
  var data = fs.readFileSync(
    "/sys/class/backlight/amdgpu_bl1/brightness",
    "utf-8"
  );

  var newData = parseInt(data) + 10;
  if (newData > 255) {
    newData = 255;
  } else if (newData < 0) {
    newData = 0;
  }
  newData = newData.toString();

  fs.writeFileSync(
    "/sys/class/backlight/amdgpu_bl1/brightness",
    newData,
    "utf-8"
  );
}

The index.html code is:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Clock App</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <button onclick="incBright()">+</button>
    <button onclick="decBright()">-</button>
    <script src="script.js"></script>
  </body>
</html>

I want to execute the inc() function when someone click on the’+’ button!
elctron js app window

Can someone tell me is that even possible to do that or not.

I am using linux

I don’t have any idea about this stuff

How do I write an IF-statement using created variables?

I have the following code, I have to create 2 new variables “pulseWidth” and “grow” and create if-statements to ask the balls drawn to grow and shrink in a pulsing manner. I am not sure as to how to write the if-statements.


  var x1 = 400;
  var x2 = 300;
  var x3 = 200; 

  var move1 = 5 ;
  var move2 = 5 ;
  var move3 = 5 ;


function setup() {
  createCanvas(800, 800);
  background(150,150,150);
}

function draw() {


 // background(150);


  fill(225, 0, 0);
  ellipse(x1, x1, x1, x1);
  x1 = x1 + move1;

  fill(0, 225, 0);
  ellipse(x2, 500, 30, x2);
  x2 = x2 + move2;

  fill(0, 0, 225);
  ellipse(x3, 400, x3, 300);
  x3 = x3 + move3;

  if ((x1 > width) || (x1<=0))
  {
    move1 = move1 * -1; 
  }
  if ((x2 > width) || (x2<=0))
  {
    move2 = move2 * -1; 
  }
    if ((x3 > width) || (x3<=0))
  {
    move3 = move3 * -1; 
  }  

  

  
}

the psuedocode I believe is in the right direction is

if  pulseWidth  >   50  or  pulseWidth  <   10  
         Multiply   grow    by  -1  to  reverse it

any help will be appreciated!

How can I fix error in html2canvas library

I was using html2canvas to convert an image in base 64 and send it through PHP and thus store it as a Blob, at first it worked correctly and when I decoded it it showed me the image, but now it shows me this error in the library and I don’t know why it happens.

The error is the following:

documentClone.replaceChild(documentClone.adoptNode(cloner.documentElement), documentClone.documentElement);

Controller can´t find local function [duplicate]

so im working my first project in php and i ran into a problem, which im not sure how to solve. I have a fairly standart init for my controller with “create”, “edit”, “delete” etc function.
Within here i have a function called “pdf”, this is gathering the data connected to the document and setting up a printable PDF view. The function is already working, but only thru direct access of the route.

Now to my problem:
They want the pdf function to be called by a button – when i call the pdf function (defined in my controller, called in my index function in the controller) It says it´s not defined. Any ideas how to bypass this? (I´m assuming i can´t see the function from within my function?)

This is some quickly written exmaple / more or less pseudo code, since i´m not at liberty to share the original code.

<?php
class UserController {
 public function index(Request $request) {
   return DataTables::of(Example::all())
      ->addColumn('action', function($row)){
        $btn = "<button onclick = 'pdf($id)'>"
       }
 }

 
 public function pdf($id) {
   //creates the pdf then
   return $pdf->stream('Example.pdf');
 }
}
?>

Thanks for any answers in advance, i hope i made my problem clear.

Export svg to png/tiff with foreignObject

Im using https://github.com/jgraph/drawio (mxgraph) for a project. I use AngularJS for frontend and NodeJS/Express for backend. The idea is to do a diagram design and then be able to export it/print it among other things.
Im able to interact with the backend and do the diagram but having trouble with the printing/rendering.
The problem is that the generated svg contains foreinObject for a QR and Barcode. While the diagram is rendered/displayed on the frontend, i need to generate a png/tiff in order to send it to a printer, but nodejs is not capable to render the foreinObject elements. I
tested canvg, sharp on node but foreignObject are not supported (according to some issues on github).

This is an example svg:

    <svg width='600' height='500'>
      <g xmlns="http://www.w3.org/2000/svg" fill="#464445" font-family="Lucida Console" pointer-events="none" text-anchor="middle" font-size="72px">
        <text x="350" y="135">ABCDEF12345</text>
      </g>
      <g xmlns="http://www.w3.org/2000/svg">
        <switch>
          <foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility">
            <div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 130px; margin-left: 300px;">
              <div style="box-sizing: border-box; font-size: 0px; text-align: center;" data-drawio-colors="color: #774400; ">
                <div style="display: inline-block; font-size: 11px; font-family: Arial, Helvetica; color: rgb(119, 68, 0); line-height: 1.2; pointer-events: none; white-space: nowrap;">
                  <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAACOCAYAAAB0WUfvAAALUElEQVR4Xu2dQbbcNBBF3awjsAqYwJB0WAHhsI1kHfnb4BBWQDoMyQT2kAGsg8Ztt/0ltUqvSt3/n9PHlxn9Lcsq1auq90p2dgP/YQEsYFpgh22wABawLQBA8A4s0LAAAME9sAAAwQewQJ8FyCB9dmPURiwAQDay0SyzzwIApM9ujNqIBQDIRjaaZfZZAID02Y1RG7GAGyCvXu6PqU0+fDxMY5ffl/9frimvX35X15X3LffBGq/uW86v1mPNa623XLe1jvI5o/aKzlM+r7Vu674WDqL3udYfyudQ94uu21onADlbxgtMADIbDIAUkFIRNxrBrcjpdVQV8bwRRmUW6+8qE5BB5oqjdz+tisObcckgZ0v1lngK8JRYcwlNidWyQvI35VBkkLz0IIOQQSDpleDSm9pVSWiRVAXE6PMojqVKY6+IYJVQittQYhXqmFXqwEHaEdpSGZUDApDc41CxzvbwkknlQNGI7Y2IZJDcAirj9u5DaWcAAkAyH1ABgBLLIO2Q9HZj1Ft7K3lYlZTReaKRFIBQYmXiQkkWo6m7t/SxxgGQ+omNqL2igcEScymxKLEosRqtDgACQAAIAHm0gLdvYJU6qkbvTe2qtOst5aLPo9YHSYekZ6eWLY6iyLYCYrSmBiDIvJMFvP0IS82xIpwi4955VYSNRmzv8wIQAAJAKtn72kwVBawKAJRYlFiUWEkmt/hr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JZdWzA5f3q60tfQZ1/ZrtinUt9/A+IwC50gLLRrQi8Bp9O9L7krm8G9px/Vw2OkqgU+m2ZNFrAZJmZE80j16/AqFSbnpfyLrSNW42/C4yiLXaJQI/GUDOdb8XIEnmMmv4dC1LyWLxlhVw55JNOdfp755n9dgtfc7o9cm6LuzQAs/NvPqGN7prgLQ2YrHRNRlEbWaFhDZJfUq0z7V+k7Se1jd6/KellLsVQNJ1TZQj4Xc1/tRx/SRG1IC/7plTnLihr3fd6m4BstT7tQ1NLdELEE/UrBHvZjZLlKjlGa2IP61vN7xIVTQPQNK1W8+yOOnp76WCNQGmEA2i16d2SUu4VNhQ+9blzU8w6C4BskY0RxTqAciykUpdqgKx4mDWvq0lWSFXL5km+raf963EVI0ao/xaBqUZLv09ev1pvVXFa+SBo8O9P4ESgDwBms+Gn+TDdANbU0UBsmamRj/Dmi8617Se87v+CxiU5LzO7RAdVsAUIkCrzKkFh+j1yzNm6tv5eb2Z/4ncJ3zbu8ogSS3sIsEna0Sc9hpwJE4x1d8edagG+FsCpAbAbM5GvybNnq2M7SlFU6+MChlhj77xgLsBSG/k8QIkutGqbAoAZCG0EvSKg9SeqTamtdaanaPXW7ZJ+j5NMePGPn7V7e4CIEnjKWxYD0BWnd9RtizWNppp81GSSl+j2XxzztsCyGkN47N9ThuRa4lTPE+apVIuYPU7eq7/Yhh+Tk8HpMS9dRznKm9+gsH3AZDGsY6TTS5Ul+IbXlW7JU7TOgZyGltTmsxjF+P1tezROnrh5VMKINZxnNr9W2uOHpUpr2+ViRHh4wn8PXxLADKarAcg1UN7jcOTFz2QCdntw5DlbqoSK3rYsnbGrQXWyPWRQ41hr33GAXcBkGe0B1NhgcwCAASHwAINCwAQ3AMLABB8AAv0WYAM0mc3Rm3EAgBkIxvNMvssAED67MaojVgAgGxko1lmnwUASJ/dGLURCwCQjWw0y+yzwP+VeiwUlWaprQAAAABJRU5ErkJggg==" />
                </div>
              </div>
            </div>
          </foreignObject>
          <text x="300" y="133" fill="#774400" font-family="Arial,Helvetica" font-size="11px" text-anchor="middle">[Object]</text>
        </switch>
      </g>
      <g xmlns="http://www.w3.org/2000/svg">
        <switch>
          <foreignObject style="overflow: visible; text-align: left;" pointer-events="none" width="100%" height="100%" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility">
            <div xmlns="http://www.w3.org/1999/xhtml" style="display: flex; align-items: unsafe center; justify-content: unsafe center; width: 1px; height: 1px; padding-top: 340px; margin-left: 450px;">
              <div style="box-sizing: border-box; font-size: 0px; text-align: center;" data-drawio-colors="color: #774400; ">
                <div style="display: inline-block; font-size: 11px; font-family: Arial, Helvetica; color: rgb(119, 68, 0); line-height: 1.2; pointer-events: none; white-space: nowrap;">
                  <div title="Diagram Title">
                    <canvas style="display: none;" width="200" height="200"></canvas>
                    <img style="display: block;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAOwklEQVR4Xu2dwYIbNw5E46Ov+abdfHSy37RXH3dHY1t2S00W8QhQ7JnKMSJAoFBFgJwZ+ctf//r3//64+H9//+efL9EUVN5Rn9Sfsuvl1Yox26fyVxFHtJ5V67+o5Ks2zvQbJfNt707e394+/hr1qXCsINEqn6/ILZMfM74skGf0LJAHTCyQGYltYBs97d1B2kU7w9IC2YDkMyFYIEf0FKGj9xrlr2LUm+FDpq1HLI9YBwTcQY6EsEAaxw0hSubJNeJrl5N7lzhGMIuusUAskChnntZ/aoGQ+X4a8aRXlF3ioDN8dvzicQJvRwWyA7cUJrKD7JDELgSjcVA7zNiOoYqF7GmBENQSbVRRV4mYxkHtEiG8u1KxkD0tEIJaoo0qqgUyDrbCctzTr5UWCEEt0UYV1QIZB1thOe7JAnlHYOVz58qT6LMS5Qp5V8TY4nLJJX2nBHqJ905DmgPpVmov4pOc9NSGxl9lR/MgBzB6xVKJr0zAAqFoj9upehPi0RN9POrnlSROCySIODntKcGCoZUtp/FX2dFELZAAcqp4LVcWSM7J7A4SIOvPpUThHrEA0EETdZhk103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KzQDbuIBXFUcRcdTCoOHq5Zwp15pBRObTilJf0maBW2SYTBT3zWiDnCFggq1TQ2ccCGS8COUmVjTvIOP4vWWmBjMOuyH6GpbKxQMbxf8lKC2QcdkV2C+SIpe8gz9zyHeQBEyWqj9xB/g8nxCcwho3KAQAAAABJRU5ErkJggg==" />
                  </div>
                </div>
              </div>
            </div>
          </foreignObject>
          <text x="450" y="343" fill="#774400" font-family="Arial,Helvetica" font-size="11px" text-anchor="middle">[Object]</text>
        </switch>
      </g>
    </svg>

And should look like this: Test svg. With sharp/canvg the QR and barcode are not displayed and instead [Object] is displayed on the final png/tiff. Even tryied C# SVG NuGet and htm2canvas for rendering on backend with same issue.

I’ve seen some posts on how to render canvas.toDataURL to png with but i dont have a object on the document DOM since mxgraph works differently and only have the final available as string. Any ideas on how can i remove the foreignObjects or how to modify the svg manually?

Is possible to “create” a canvas element and render the svg inside and then export it?

How to find index of first duplicate in array in Javascript?


    const numbers = [2, 4, 5, 2, 3, 5, 1, 2, 4];

I need to create the function indexOfRepeatedValue (array). Use numbers that are stored in the variable numbers.

I should create a variable firstIndex in this function. In the for loop, check which number repeats first and assign its index to firstIndex. Then write this variable to the console – outside of the for loop.

I came up with this idea:


    function indexOfRepeatedValue(array){
        let firstIndex;
        for (let i=0; i < array.length; i++ )
            if (firstIndex.indexOf(array[i]) === -1 && array[i] !== '');
        firstIndex.push(array[i]);
        return firstIndex;
    }
    
    indexOfRepeatedValue(numbers);

It doesn’t work at all. I’m lost, some piece of advice?