title: circular structure to JSON in react
body: <p>I have this variable on my component's state:</p>
  
  <pre><code>chartData: {
              labels:null,
              datasets:null
          }
  </code></pre>
  
  <p>I receive this json from my api to create the chart:</p>
  
  <pre><code>{
  "labels": [
      "13/7",
      "14/7",
      "15/7"
  ],
  "datasets": [
      {
          "label": "%%%%",
          "data": [
              0,
              18,
              168
          ],
          "backgroundColor": [
              "rgba(255, 99, 132, 0.6)",
              "rgba(255, 99, 132, 0.6)",
              "rgba(255, 99, 132, 0.6)"
          ]
      }
  ]
  </code></pre>
  
  <p>}</p>
  
  <p>The chart appears with no problem but when I try to print the value of this.state.chartData this appears:  </p>
  
  <p>TypeError: Converting circular structure to JSON
      --> starting at object with constructor 'HTMLCanvasElement'
      |     property '__reactInternalInstance$khbtn4bp50s' -> object with constructor 'FiberNode'
      --- property 'stateNode' closes the circle</p>
  
  <p>Here is the setState of the variable:</p>
  
  <pre><code>this.setState({
          chartData: {
  
              datasets: response.datasets,
              labels:response.labels
          }
      })
  </code></pre>
  
  <p>the response is the json above.</p>
  
  <p>UPDATED METHOD JUST TO PRINT VALUES:</p>
  
  <pre><code> teste=()=&gt;{
  
      alert("chart data")
  
      alert(JSON.stringify(this.state.chartData))
  
  }
  </code></pre>
  
  <p>edit1: print of the console.log(this.state.chartData)</p>
  
  <p><img src="https://i.stack.imgur.com/8wMRS.png" alt="enter image description here"></p>
  
  <p>edit 2: api call:</p>
  
  <pre><code>    return fetch(url, {
  
          method: 'POST',
          headers: {
              'Accept': 'application/json',
              'Content-Type': 'application/json',
              'Access-Control-Allow-Origin': '*'
          },
          body: JSON.stringify({
              labels:params.labels,
              datasets:params.datasets
          })
  
      }).then(response =&gt; response.json())
          .then(json =&gt; {
              console.log("fetchJsonFromApi " + JSON.stringify(json))
              // making callback optional
              if (callback &amp;&amp; typeof callback === "function") {
                  callback(json);
              }
              return json;
          })
          .catch(error =&gt; {
              console.log(error)
          });
  
  }
  </code></pre>