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

184
Views
How to change number of columns responsively using useMemo hook in react.js?

It returns fixed column numbers, when you add more contacts it will always be 3 columns, and I need to change numbers for responsive design, like it should be 2 columns or 1 based on screen resolution.

const contactsCollsMemo = useMemo(() => {
    return contactsData?.reduce((acc, contact, i) => {
      acc[i % 3] = (acc[i % 3] || []).concat(contact);
      return acc;
    }, {} as { [key: string]: Contact[] });
  }, [contactsData]);
  
return (
  <div className="contacts-wrapper">
     {Object.keys(contactsCollsMemo || {}).map((key) => (
         <ContactBlock key={key} contacts={contactsCollsMemo[key]} />
     ))}
  </div>
)
//component ContactBlock:
<div className="contacts-block">
      {contacts.map((contact) => (
        <div key={contact.id} className="contacts-info">
          <div className="contacts-name">{contact.name}</div>
          <div className="contacts-phone">Тел.: {contact.phone}</div>
          <div className="contacts-email">E-mail: {contact.email}</div>
        </div>
      ))}
 </div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To make the number of columns response based on the screen size, you can do it using the media queries https://www.w3schools.com/css/css_rwd_mediaqueries.asp & display grid-template in CSS https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template.

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!