React Native ReferenceError:找不到变量:myData

问题描述

我正在尝试将变量 myData 传递给 MAINrender 函数,后者又会将其传递给我的组件 业务流程管理。我不断收到参考错误。最终,目标是将 myDataMAIN 传递到 BPM,其中 myData 将是在屏幕上绘制并输出。我只是在尝试在渲染函数中实际使用 myData 时遇到错误。新的反应原生。我已经验证了文档,看起来我的语法没有错。会不会漏掉一个逻辑问题?感谢您的帮助。

const BPM=(props)=>{
  
   //const myData= [1,2,4,5,6,7,3];
return(
  <LineChart
      data={{
      title: "Beats per minute",withVerticalLabels: true,withHorizontalLabels: true,datasets: [
        { data: 
        props.data
        }
      ]
    }}
    width={screenWidth} // from react-native
    height={220}

    chartConfig={
      chartConfig
    }
    bezier
    style={{
      marginVertical: 8,borderRadius: 16
    }}
  />

)

}



export default class ProfileScreen extends Component {

  
  MAIN = async (idToken,accesstoken) =>{
    const fit_data= await GFIT(accesstoken,idToken)
    UPLOAD_FIT_DATA(accesstoken,idToken,fit_data)
    const myData= (FORMAT_FIT_DATA(fit_data))

    }
    render() {

    return (
      <View style={styles.container}>
        <Text> Profile Screen </Text>
        <Text style={{ fontSize: 20,fontWeight: "bold" }}>
          Welcome,{this.props.navigation.getParam("username")
          }
        </Text>
        <Button
          title="Update My Dashboard"
          onPress={() =>{this.MAIN(this.props.navigation.state.params.idToken,this.props.navigation.state.params.accesstoken)}}
        />
        <Text>
        {this.myData}
        </Text>
      <Calendar />
        <BPM  data={myData}/>



        <Button
          title="Sign out"
          onPress={() => this.props.navigation.navigate("Login")}
        />
      </View>
    );
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)