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

131
Views
react - how to extract props to share

Let's assume I have 2 inputs below, which share the same value of props except className

    <ReactCardFlip>
      <input
        type="text"
        maxLength={1}
        className={inputStyles.input}
        defaultValue={value}
      />
      <input
        type="text"
        maxLength={1}
        className={`${inputStyles.input} ${inputFlipClass}`}
        defaultValue={value}
      />
    </ReactCardFlip>

Apart from creating new component, is it possible to share the props like

    <ReactCardFlip>
      <input
        {...inputProps}
        className={inputStyles.input}
      />
      <input
        {...inputProps}
        className={`${inputStyles.input} ${inputFlipClass}`}
      />
    </ReactCardFlip>

?

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

0

Yes you can. You can also create a props getter (a term coined by Kent C Dodds) for the input


const getInputProps = (config) => ({
  type: "text",
  maxLength: 1,
  defaultValue: value,
  ...config,
})


return (
  <ReactCardFlip>
    <input
      {...getInputProps({ className: inputStyles.input })}
    />
    <input
      {...getInputProps({ 
        className: `${inputStyles.input} ${inputFlipClass}` 
      })}
    />
  </ReactCardFlip>
);
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!