Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
How to rewrite code into one using javascript and react?

i have two methods like below.

 const handleRowClick = React.useMemo(() =>
     !isRunning
         ? (itemId: string) => {
             startRun({items: [itemId] });
         }
         : undefined,
     [startRun]
 );

  const handleSelectedItemsClick = React.useMemo(() =>
      !isRunning
          ? (items: string[]) => startRun({ items: items })
          : undefined,
          startRun]
  );

  handleRowClick(itemId);
  handleSelectedItemsClick(itemIds);

as seen from above handleRowClick takes a string as an argument whereas handleSelectedItemsClick takes an array of strings as an argument.

how can I rewrite the above methods into one such that it can handle either a string or array of strings as input?

could someone help me with this? thanks.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

at function param set the the type string | string[]

the inside a function

(itemId: string | string[]) => {startRun({items: Array.isArray(itemId)?itemId:[itemId] });}

about 4 years ago · Juan Pablo Isaza Report

0

const handleSelectedItemsClick = React.useMemo(() =>
    !isRunning
    ? (items: string[]) => startRun({ items: items })
    : undefined,
    [startRun]
);

const handleRowClick = (itemId) => {
    handleSelectedItemsClick([itemId]);
}

handleRowClick(itemId);
handleSelectedItemsClick(itemIds);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!