I am returning a map that outputs a list and storing this in a state with html and text which is passed to an error component. problem is the list is displayed as an object and the html is displayed as raw text and not being translated.
the below code is set and passed in to a component
let fwobjectList = fwobject.map(function(name, index) {
console.log(name.id);
console.log(name);
console.log(index);
return <li key={index}>{name.id}</li>;
});
this.setState({
showError: true,
errorMsg: `You cannot delete rows where FW Object names have been used. Please unselect row id's<ul>' + ${fwobjectList} + '</ul>`
});
component calls the error modal in render
return (
<div className="container-fluid">
...
<ModalError
title={this.state.errorTitle}
body={this.state.errorMsg}
show={this.state.showError}
handleCloseError={this.handleCloseError}
/>
...
)
my render function in the error modal.
render(){
let title = 'Error';
let body = 'Unexpected error occured';
if(this.props.title.length > 0){
title = this.title.body;
}
if(this.props.body.length > 0){
body = this.props.body;
}
return (
<Modal
id="myModalError"
className="modal fade"
role="dialog"
show={this.props.show}
>
<Modal.Header closeButton className="modal-header alert alert-danger">
<Modal.Title>{title}</Modal.Title>
</Modal.Header>
<Modal.Body>
{body}
</Modal.Body>
<Modal.Footer>
<Button onClick={this.handleCloseError}>Close</Button>
</Modal.Footer>
</Modal>
);
}
the output i see in the browser is
"You cannot delete rows where FW Object names have been used. Please unselect row id's<ul>' + [object Object] + '</ul>"
i want the following printed
"You cannot delete rows where FW Object names have been used. Please unselect row id's
- 123
- 234
- 456
"
UPDATE
if i use example from this link Insert HTML with React Variable Statements (JSX) i get the following
You cannot delete rows where FW Object names have been used. Please unselect row id's
' +
3043
+ '
UPDATE 2
I managed to do fwobjectIds.join().toString()
but this leaves a comma in between which i do not want. how to remove the comma.
You cannot delete rows where FW Object names have been used. Please unselect row id's
3043
,
3042