Open Dataからデータをプルして、クイックヒートマップをまとめようとしています。その過程で、いくつかの統計を追加したいと思います。データがあり、マップをレンダリングできるという点で、ほぼすべてがうまくいきますが、データが入るまでに時間がかかるため、データを取得した後の計算の処理方法がわかりません。どのように設定すれば、まだデータを受信していない場合でも、状態変数に対して関数を実行できますか?現在、StatCardに小道具として渡される数値としてnullを取得しています。
以下は私の試みです:
App.js
  import React, { Component } from 'react';
import Leaf from './Leaf';
import Dates from './Dates';
import StatCard from './StatCard';
import classes from './app.module.css';
class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      data:[],
      cleanData:[],
      dateInput: '2019-10-01',
      loading: false,
      totalInspections: null,
      calculate: false
    };
  }
  componentDidMount() {
    try {
      this.fetchData();
    } catch (err) {
      console.log(err);
      this.setState({
        loading: false
      })
    }
  }
  fetchData=()=>{
    const requestData = async () => {
      await fetch(`https://data.cityofnewyork.us/resource/p937-wjvj.json?$where=latitude > 39 AND latitude< 45 AND inspection_date >= '${this.state.dateInput}'&$limit=50000`)
        .then(res => res.json())
        .then(res =>
          //console.log(res)
          this.setState({ data: res, loading: true})
        )
    }
    const  calculateInspections = () => {
      this.setState({totalInspections: this.state.data.length})
    }
    //call the function
    requestData();
    if(this.state.data) {
      calculateInspections();
    }
  }
  handleDateInput = (e) => {
    console.log(e.target.value);
    this.setState({dateInput:e.target.value, loading: false}) //update state with the new date value
    this.updateData();
    //this.processGraph(e.target.value)
  }
  updateData =() => {
    this.fetchData();
  }
  LoadingMessage=()=> {
    return (
      <div className={classes.splash_screen}>
        <div className={classes.loader}></div>
      </div>
    );
  }
  //inspection_date >= '${this.state.dateInput}'& 
 // https://data.cityofnewyork.us/resource/p937-wjvj.json?$where=inspection_date >= '2019-10-10T12:00:00' 
  render() {
    return (
      <div>
        <div>{!this.state.loading ? 
              this.LoadingMessage() : 
              <div></div>}
        </div>
        {this.state.totalInspections && <StatCard totalInspections={this.state.totalInspections} /> }
          <Dates handleDateInput={this.handleDateInput}/>
          <Leaf data={this.state.data} />
      </div>
    );
  }
}
export default App;
StatCard.js
import React from 'react';
const StatCard = ( props ) => {
    return (
        <div >
            { `Total Inspections: ${props.totalInspections}`}
        </div>
    )
};
export default StatCard;修理を試みる
   componentDidMount() {
    try {
      this.fetchData();
    } catch (err) {
      console.log(err);
      this.setState({
        loading: false
      })
    }
  }
  componentDidUpdate () {
    if(this.state.data) {
      this.setState({totalInspections: this.state.data.length})
    }
  }
  fetchData= async ()=>{
    const requestData = () => {
    fetch(`https://data.cityofnewyork.us/resource/p937-wjvj.json?$where=latitude > 39 AND latitude< 45 AND inspection_date >= '${this.state.dateInput}'&$limit=50000`)
        .then(res => res.json())
        .then(res =>
          //console.log(res)
          this.setState({ data: res, loading: true})
        )
    }
    //call the function
    await requestData();
  }
this.setState({ data: res, loading: true})にタイプミスrequestData機能は?データがフェッチloadingされるfalseときに設定されるべきではありませんか?