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

162
Views
pass div to props react without children

I'm trying to pass a <div></div> (some html/jsx content) into a FC but not from the children props (it's already used for something else).

I wanna have something like that:

<Component props={{ 
  title: "hello",
  description: 
    {
      <>Hello <h1>world</h1> </>
    }
/>

How can I do that ?

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

0

Update :

You can use Fragment if your version is above 16.2 :

like this :

<Child
    text={
          <Fragment>
            This is an <strong>HTML</strong> string.
          </Fragment>
        }
      />

Older version :

You can use dangerouslySetInnerHTML to render a HTML content from a prop.

pass the html as a normal string prop

<Component text="This is <strong>not</strong> working." />

And render in in the JSX code like this:

enter code here :

<div className="header-title-right wow fadeInRight" dangerouslySetInnerHTML={{__html: props.text}} />

Just be careful if you are rendering data entered by the user. You can be victim of a XSS attack

Here's the documentation: https://facebook.github.io/react/tips/dangerously-set-inner-html.html

Example : Working Demo

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!