I created a rails 6 Blog application using Action Text/Active Storage, the image loads fine on the rails server. But when i am using the api call to fetch the json and using the dangerouslySetInnerHtml afterwards in react to convert raw html, it is not rendering the image stored by Action Text in the db.
I know that react does not support the "Action-text-attachment" tag which is stored in the database, but can anyone refer a better workaround or suggestion through this method it has been driving me crazy.
Api Call
{
"id": 5,
"created_at": "2020-12-07T11:34:27.443Z",
"updated_at": "2020-12-14T14:06:53.671Z",
"title": "One in five deaths in North Wales now being caused by Covid-19",
"topic_id": 1,
"user_id": 1,
"status_id": 2,
"rich_text_body": {
"id": 5,
"name": "body",
"body": "<div><action-text-attachment content-type=\"image\" url=\"https://i2-prod.dailypost.co.uk/incoming/article18128897.ece/ALTERNATES/s615/1_WORLD_Coronavirus_185952.jpg\" width=\"615\" height=\"409\" caption=\"Electron microscope image from the US National Institutes of Health showing the SARS-CoV-2 virus which causes Covid-19\"></action-text-attachment><br><br>According to figures released yesterday by the Office for National Statistics, there were 24 Covid deaths across North Wales during the week – up from 22 the week before, and 10 the week before that.<br><br></div><div>Of these, 16 Covid deaths were in hospitals, up from 13 the previous week, with eight deaths in care homes, the same as the preceding week.<br><br></div><div>Up to November 13, the pandemic had claimed a total of 664 lives across North Wales.<br><br></div><div>Of those deaths, most (530) took place in hospital, with 107 in care homes.<br><br></div><div>There were also 19 deaths recorded at home, five in hospices, two in other communal establishments, and one elsewhere.<br><br></div><div>Other communal establishments include prisons, halls of residence, hotels, and sheltered accommodation. “Elsewhere” covers deaths outside and people declared dead on arrival at hospital.<br><br></div><div>The figures are based on deaths where <a href=\"https://www.dailypost.co.uk/all-about/coronavirus\"><strong>Covid-19</strong></a> is mentioned on the death certificate.<br><br></div><div>Separate statistics from the Care Inspectorate Wales (CIW) show 12 deaths involving coronavirus among care home residents in North Wales in the week ending November 20.<br><br></div><div>This was up from nine the week before.<br><br></div>",
"record_type": "Blog",
"record_id": 5,
"created_at": "2020-12-07T11:34:27.448Z",
"updated_at": "2020-12-07T11:34:27.448Z"
},
React component
import React, { Component } from 'react'
import axios from 'axios'
class BlogsContainer extends Component {
constructor(props) {
super(props)
this.state = {
blogs: []
}
}
getBlogs() {
axios.get('blogs')
.then(response => {
this.setState({blogs: response.data})
})
.catch(error => console.log(error))
}
componentDidMount() {
this.getBlogs()
}
render() {
return (
<div>
<div className="listWrapper">
<ul className="taskList">
{this.state.blogs.map((blog) => {
return(
<li className="display-blog" blog-source={blog} key={blog.id}>
<label className="blog-title">{blog.title}</label>
<div dangerouslySetInnerHTML={{__html: blog.rich_text_body.body}} />
</li>
)
})}
</ul>
</div>
</div>
)
}
}
export default BlogsContainer