I have to display the raw HTML in the react-data-table-component. I have raw HTML which is coming from API, now I want to display that HTML in react-data-table-component.
const columns = [
{ name: 'status', selector: row => row.status}
];
const [list, setList] = useState([]);
useEffect(() => {
const fetchData = async () => {
try {
const response = await axios.get(route('users.get-users-list')); // Your API endpoint
setList(response.data);
} catch (err) {
setError(err);
} finally {
setLoading(false);
}
};
fetchData();
}, []);
<DataTable
columns={columns}
data={list}
pagination
/>
The HTML appears literally rather than as HTML:
I need to display the html in react-data-table-component how to do that
You can try format and dangerouslySetInnerHTML
{
name: "status",
selector: (row) => row.status,
format: (row) => (
<span dangerouslySetInnerHTML={{ __html: row.status }}></span>
),
},