Render HTML in React Native

前端 未结 6 1179
陌清茗
陌清茗 2020-11-29 04:03

In my React Native app, I am pulling in JSON data that has raw HTML elements like this:

This is some text. Let’s figure out...

6条回答
  •  星月不相逢
    2020-11-29 04:28

    Edit March 2017: the html prop has been deprecated. Use source instead:

    Here I am

    '}} />

    https://facebook.github.io/react-native/docs/webview.html#html

    Thanks to Justin for pointing this out.


    Edit Feb 2017: the PR was accepted a while back, so to render HTML in React Native, simply:

    Here I am

    '} />

    Original Answer:

    I don't think this is currently possible. The behavior you're seeing is expected, since the Text component only outputs... well, text. You need another component that outputs HTML - and that's the WebView.

    Unfortunately right now there's no way of just directly setting the HTML on this component:

    https://github.com/facebook/react-native/issues/506

    However I've just created this PR which implements a basic version of this feature so hopefully it'll land in some form soonish.

提交回复
热议问题