I am pushing my items in an array (table format) and then I am showing
that array in the table but it gets undefined.
class Invoice extends Component{
state= {
addItems = [];
}
template=()=>{
let items = "";
let items_array = [];
for(let i=0;i<this.state.addItems.length;i++)
{
items = (
<tr>
<td></td>
</tr>
)
items_array.push(items);
}
const html=`
<html>
<body>
<table>
<thead>
<tr>
<th>Item Name</th>
</tr>
</thead>
<tbody>
${items_array}
</tbody>
</table>
</body>
</html>
`
return html;
}
printToFile = async () => {
const html = this.template();
const { uri } = await Print.printToFileAsync({
html,
});
}
render(){
return(
<Button onPress={this.printToFile}>Print</Button>
)
}
}
Can anyone figure out what’s wrong with the code.