Search code examples
reactjsconsole

react can not show console log variable


why my log not showing anything ? is ths because the variable isLoading state ?

my code :

 function getColumns(data) {
  const columns = [];
  const sample = data[0];

  console.log("theSample" + sample);

enter image description here

and i call it from here :

class App extends React.Component {
  constructor() {
    super();
    this.state = { isLoading: true };

    if (this.state.isLoading === false) {
      //const data = getData();  
      const data = this.state.dataExt;     
     // console.log(data);

      const columns = getColumns(data);
      this.state = {
        data,
        columns,
        visible: false
      };
    }
  }

Solution

  • Because, you only call getColumns when this.state.isLoading === false, and the initial value of your isLoading state is true. Therefore, unless you update your isLoading state, getColumns wouldn't be called and your log wouldn't show up.