score:3

Accepted answer

you need to create it react way. your createtable method should look something like below.

createtable(tabledata) {
 return (
  <table>
   <tbody>
   {
    tabledata.map(rowdata => {
      return (<tr key={rowdata.id}>
          {
           rowdata.map(celldata => {
              return (<td key={celldata}> {celldata} </td>);
           })
          }
        </tr>);
    })
   }
  </tbody>
  </table>
 )

note: you need to put in a unique key for the root of jsx inside the 'maps'. identify the unique key for each iteration. as a last resort you can use index, but that is not recommended.

edit: updated for new changes

in your updated code, the td is empty and hence its displayed empty on the page.

other changes you would require

your initial state should not generate an jsx. it should be used only to compute the initial state and return a plain object. you are returning a object that contains array of jsx elements in it, which fundamentally defeats the purpose of react that it needs to require the dom to be dynamically updated appropriately based on prop/state changes. your initialstate should only contain the data that is required to construct the needed dom elements.

getinitialstate() {
    var array = [];
    var cellsarray = [];
    for (var i = 0; i < size; i ++) {
        array.push(cellsarray);
        for (var j = 0; j > size; j++) {
            array[i].push(/* push data that you need to construct your cell */);
        }
    }

    return {
        array: array
    };

}

then in your tabledata function , you need to form the required jsx. this function is getting called inside of render which is perfectly fine place to produce the dom elements.

var tabledata = this.state.array.map(rowdata => {
    i++
    return (
        <tr key={i}>
            {
                rowdata.map(celldata => {
                    return <cell key={celldata} data={celldata} start={this.props.start} />
                })
            }
        </tr>
    );
})

finally in your cell, render method you need to pass some children for td for it to be visible on the screen. in you question its empty and so the image you have posted showing the dom elements and it being empty is the right behaviour. you need to do something like below

render() {
    return (<td onclick = {this.handleclick} classname={this.state.selected ? "cell selected" : "cell"}>
 {this.props.data }
 { /*  or whatever data you want to be put here */ }
  </td>);
 }

Related Query

More Query from same tag