I have written a function to generate a html table in a string:
board = "<table className='Board'><tbody><tr key="0"><Cell key="0-0" isLit={true} /><Cell key="0-1" isLit={true} /><Cell key="0-2" isLit={true} /><Cell key="0-3" isLit={true} /></tr><tr key="1"><Cell key="1-0" isLit={true} /><Cell key="1-1" isLit={true} /><Cell key="1-2" isLit={true} /><Cell key="1-3" isLit={true} /></tr><tr key="2"><Cell key="2-0" isLit={true} /><Cell key="2-1" isLit={true} /><Cell key="2-2" isLit={true} /><Cell key="2-3" isLit={true} /></tr><tr key="3"><Cell key="3-0" isLit={true} /><Cell key="3-1" isLit={true} /><Cell key="3-2" isLit={true} /><Cell key="3-3" isLit={true} /></tr><tr key="4"><Cell key="4-0" isLit={true} /><Cell key="4-1" isLit={true} /><Cell key="4-2" isLit={true} /><Cell key="4-3" isLit={true} /></tr><tr key="5"><Cell key="5-0" isLit={true} /><Cell key="5-1" isLit={true} /><Cell key="5-2" isLit={true} /><Cell key="5-3" isLit={true} /></tr></tbody></table>"
If I format it in VSCode, I will a proper table:
<table className='Board'>
<tbody>
<tr key="0">
<Cell key="0-0" isLit={true} />
<Cell key="0-1" isLit={true} />
<Cell key="0-2" isLit={true} />
<Cell key="0-3" isLit={true} />
</tr>
<tr key="1">
<Cell key="1-0" isLit={true} />
<Cell key="1-1" isLit={true} />
<Cell key="1-2" isLit={true} />
<Cell key="1-3" isLit={true} />
</tr>
<tr key="2">
<Cell key="2-0" isLit={true} />
<Cell key="2-1" isLit={true} />
<Cell key="2-2" isLit={true} />
<Cell key="2-3" isLit={true} />
</tr>
<tr key="3">
<Cell key="3-0" isLit={true} />
<Cell key="3-1" isLit={true} />
<Cell key="3-2" isLit={true} />
<Cell key="3-3" isLit={true} />
</tr>
<tr key="4">
<Cell key="4-0" isLit={true} />
<Cell key="4-1" isLit={true} />
<Cell key="4-2" isLit={true} />
<Cell key="4-3" isLit={true} />
</tr>
<tr key="5">
<Cell key="5-0" isLit={true} />
<Cell key="5-1" isLit={true} />
<Cell key="5-2" isLit={true} />
<Cell key="5-3" isLit={true} />
</tr>
</tbody>
</table>
And if I cut and paste directly into an react component in the render, it will show a table.
However, if I were to display the string using a variable,
render() {
return (
<div>
{board}
</div >
)
}
I won't get the table. It just show a string.
I've tried adding "\n" and < br > but it does not show a table.
How do I display the table from this string ?
Thanks.