So I have a module that renders a calender for the current month. It looks like this.
let days = {0: 'Sun', 1: 'Mon', 2: 'Tue', 3: 'Wed', 4: 'Thu', 5: 'Fri', 6: 'Sat'};
let today = new Date();
today.setDate(1);
let dayOfWeek = today.getDay();
let count = 0;
class Calender extends Component {
constructor(props) {
super(props);
this.calRender = this.calRender.bind(this);
}
calRender(x) {Object.keys(days).map(index => {count++;
return <td key={x+index} style={{...styleVars.defaultTextColor, ...styleVars.blockSize, backgroundColor: '#777'}}>{count}</td>})}
render() {
return(
<table>
<tr>
{Object.keys(days).map((index) => <th key={index} style={{...styleVars.defaultTextColor, ...styleVars.blockSize, backgroundColor: '#232'}}>{days[index]}</th>)}
</tr>
<tr>
{Object.keys(days).map(index => {
if(index < dayOfWeek) {
return <td key={index} style={{...styleVars.defaultTextColor, ...styleVars.blockSize, backgroundColor: '#bbb'}}></td>}
else {count++;
return <td key={index} style={{...styleVars.defaultTextColor, ...styleVars.blockSize, backgroundColor: '#777'}}>{count}</td>}
})}
</tr>
<tr>
{this.calRender(7)}
</tr>
<tr>
{this.calRender(14)}
</tr>
<tr>
{this.calRender(21)}
</tr>
<tr>
{this.calRender(21)}
</tr>
</table>
)
}
}
The problem is that calRender function is not returning anything, even though it is supposed to return tags with dates. When I am doing this without a function(by writing map statements for each tag), it is working fine. Please suggest where I have messed this up.