I'm doing a call to an API that returns some HTML:
example:
<p>Hello there</p><p>Javascripti</p>
I want to use this in my React Native app but this time I want to replace all the <p> tags for <Text> because that is something I can use in React Native.
How can I achieve something like this? I can't find out how to translate or parse HTML.
EDIT: I used Regex to make the <p> a <Text> but it just returns a string. It displays this on the screen: <Text>Lorem Ipsum</Text. How can I parse this to readable JSX?
JSX is basically syntax sugar (as seen here, here and especially here) for calling createElement:
React.createElement(component, props, ...children)
So once you've captured the text inside the <p></p> tags you can generate any tag like this:
let capturedContent = 'Hello there'
const element = React.createElement('Text', { }, capturedContent)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With