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

130
Views
Need to retrieve html from axios request

I am using axios to send a request to a resource that is exposing html on the backend. When I send the GET request I receive an object as a response. When I print the response with console.log() it breaks the React application due to the response being an object and not the html I am expecting.

Currently I am trying to specify responseType: 'document' in the config. But that doesn't seem to work. I still get an object with the error being:

"Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead."

Ultimately I need to end up with a <div></div> that I can embed in my React page.

import axios from 'axios';

const examplePage = "example.com/example"

export const requestExamplePage = async () => {
    const {data} = await axios.get(examplePage, {responseType: 'document})
    
    return data
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The error:

"Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead."

Actually means that you're trying to render a promise. Are you sure thats the right way of destructuring the request? data has to be a html wrapped in double quotes (string) and you also need dangerouslySetInnerHtml to inject it into a div.

Try this:

export const requestExamplePage = async () => {
    const {data} = await axios.get(examplePage, {responseType: 'document'})
    
    return (
        <div dangerouslySetInnerHTML={{ __html: data }} />
    )
}

Make sure that data is an an actual html string.

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!