I'm using typescript. I'm having a column value in the table as
val desc = "<div><p>testing</p></div>"
I want to render this as testing in value. I'm using
react-table
I tried new DOMParser().parseFromString("<div><p>testing</p></div>", "text/html")
But got error as
Error: Objects are not valid as a React child (found: [object HTMLDocument]). If you meant to render a collection of children, use an array instead
Here is my react-table code:
<Table
data={data}
headers={headers}
searchable={true}
searchPlaceholder={'Search Apps'}
toolBarButtons={toolBarButtons}
/>
const headers = useMemo(
() => [
{
Header: <LeftHeader>{checkbox}</LeftHeader>,
accessor: 'Checkbox',
disableSortBy: true,
},
{
Header: <LeftHeader>Name {sortIcon}</LeftHeader>,
accessor: 'Name',
},
{
Header: <LeftHeader>Type {sortIcon}</LeftHeader>,
accessor: 'Type',
},
{
Header: <LeftHeader>Tenancy {sortIcon}</LeftHeader>,
accessor: 'Tenancy',
},
{
Header: <LeftHeader>Description {sortIcon}</LeftHeader>,
accessor: 'Description',
},
{
Header: <LeftHeader>Action</LeftHeader>,
accessor: 'Button',
disableSortBy: true,
},
],
[],
)
const data = useMemo(() => {
return List.map((ap) => {
const actionButton = (
<Edit
size={20}
cursor={'pointer'}
color={'#1E95DE'}
onClick={() => setRedirectUrl(RouteConstants.Marketplace + '/' + ap.id)}
/>
)
checkbox = <input type={'checkbox'} onChange={(e) => handleInputChange(e, ap)} />;
return {
Checkbox: checkbox,
Name: ap.stuName,
Type: options.filter(e => e.value === ap.stuType).map(f => {
return f.label
}),
Description: ap.studescription,
Tenancy: titleCase(ap.stuTenancy),
Button: actionButton,
};
})
}, [List])
How can I achieve this?
descis defined as"<div><p>testing</p></div>"(string) and not as<div><p>testing</p></div>(React element)? If not, just remove the quotes and you should be fine.react-table?