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

235
Views
Dynamically creating react component from fetched data

I am trying to build a fill-in-the-blank style component. It consists of some text with one or more input boxes inside the text. The number and location of the input boxes varies from text to text so the component must be dynamically built. My question is: what is the best way to store this on a database and fetch it for rendering?

My attempt at a solution:

  1. Create a component which has the text and input boxes appropriately placed
  2. Store the entire component JSX in the database and fetch it when requested
  3. Render the fetched JSX in a container component

I think this would work but I'm wondering if there is a better way since it seems a bit hacky to store the entire component JSX on a database.

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

0

Do not store the entire element inside the database. You just need to store the relevant data that will go inside the input object:

For example:

initialValue, value, type, placeholder, label, isTextArea, ...etc

Then when you fetch data:

const [inputData, setInputData] = useState(iunitialInputData)

useEffect(() => {
//Fetch input data from DB
data = apiCall()
setInputData(data)
})

return (
//render inputs here

{ inputData?.length? inputData.map(item => {

//Put data inside here
return(
<input value={item.value} placeholder={item.placeholder} />
)
}) : <p>No data!</p>
}
)
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!