How to Use Raw Html in Bucklescript-TEA

Having trouble trying to display some html code in Bucklescript-TEA?

Maybe you scraped some site data and have certain sections with complete html code and don’t want to further parse it, so you just want to display it?

Or there’s some html element Bucklescript-TEA doesn’t support?

Perhaps, you just have some raw html already stored in database and need to display it?

Since Bucklescript-TEA doesn’t really allow you to pass ‘raw’ html into a text field, you’ll to find another solution.

Here’s the one I came up with:

let innerHTML html =
  Vdom.prop "innerHTML" html
	
(* and then just use it where you need it, like with any attribute *)

div [ class' "message"; innerHTML "<p>Hello There!</p>" ] []

Note - Please be aware, you don’t want to do this with any user-generated content. It can be a security issue, so be careful if you need to use this.

So it’s a simple as that!

Comments