I have a very niche issue where I am trying to pass a block of executable code as a prop options
. The prop looks like this...
columns={[
{
name: "Fund Name", //Title
width: "40%", //Colum Width
options: {[
var splitValue = value.split("//");
return (
<div className="fundName">{splitValue[0]}<p>{splitValue[1]}</p></div>
);
]}
}, {
name: "Review Date",
width: "20%"
}, {
name: "Company Debt",
width: "20%"
}, {
name: "Alerts",
width: "10%",
options: {[
return <Alerts {data: value} />
]}
}
}
So sometimes there are some variables and additional code and sometimes it may just be returning a component. Anyway. I need the code to look like this in the component...
const columns = [{
name: "Fund Name",
options: {
customBodyRender: (value, tableMeta, updateValue) => {
var splitValue = value.split("//");
return (
<div className="fundName">{splitValue[0]}<p>{splitValue[1]}</p></div>
);
}
}
}, {
name: "Review Date"
}, {
name: "Company Debt"
}, {
customBodyRender: (value, tableMeta, updateValue) => {
return <Alerts {data: value} />
}
}];
So firstly. Is this possible? can I pass variables like the splitValue, and, will it pick up that the passed in "value" variable is to be associated with the customBodyRender: (value,....
variable?
Here is my attempt but it is throwing a lot of errors. I feel I may be close if it even at all possible....
let columns = this.props.columns.map(item =>
item.options
? ({ ...item, options: { customBodyRender: (value, tableMeta, updateValue) => { eval(item.options) }} })
: item
);
Thanks