0

I want to keep the HTML tag from response in react native

the response from postman:

{
    "enable": true,
    "faq": [
        {
            "answer": "<ol>some text</ol>",
            "question": "question?"
        }
    ]
}

code in react native are :


doGet(url, additionalHeaders, shouldEncodeURI = true) {
        var containAuthorization = (additionalHeaders !== undefined && additionalHeaders.Authorization !== null);
        const [headers] = this.generateHeaderBody(null, 'application/json', additionalHeaders);
        const encodedUrl = shouldEncodeURI ? encodeURI(url) : url;
        const dataObj = {
            additionalHeaders,
            containAuthorization
        };
        return new Promise((resolve, reject) => {
            fetch(encodedUrl, this.getReqConfig("GET", headers, null)).then(initialResponse => {
                console.log('>>> initial ', JSON.stringify(initialResponse));
                dataObj['initialResponse'] = initialResponse;
                this.responseHandlerGet(url, dataObj, resolve, reject);
            }).catch(error => {
                if (error && error.status) {
                    dataObj['initialResponse'] = error;
                    this.responseHandlerGet(url, dataObj, resolve, reject);
                } else {
                    reject(error);
                }
            });
        });
    },

instead of return <ol> some text </ol> the code returning some text

did my code auto delete the HTML tag? or there is some unusual behavior? or even that is normal?

so if want to keep the html tag is there a way of it?

HendyCrcs
  • 111
  • 11

1 Answers1

0

if you want to keep HTML in your response

then keep your API header

"Content-Type": "text/html"

You need to pass this

const [headers] = this.generateHeaderBody(null, 'text/html', additionalHeaders);
Raj Parmar
  • 83
  • 6
  • this is still not working for me, but when i load with postman i use ```Content-Type: "application/json" is working fine – HendyCrcs Jun 12 '23 at 01:20
  • Try to console log response Did you get HTML Tag in consolelog ?? if you are getting HTML tag in response then try this [link](https://stackoverflow.com/questions/29334984/render-html-in-react-native) – Raj Parmar Jun 12 '23 at 04:45
  • When I do console log after apps get return from service, the html tag suddenly removed automatically from code above – HendyCrcs Jun 12 '23 at 05:56