Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当传递给助手时,setState函数显示为未定义_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 当传递给助手时,setState函数显示为未定义

Javascript 当传递给助手时,setState函数显示为未定义,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我正在尝试拍摄一张照片,当照片在后台返回其预测时,更新状态。但是,我无法让函数传入,它只是作为未定义的函数出现。我知道redux可能是最好的解决方案,但这是整个应用程序中唯一一个我有问题的状态,所以如果可能的话,我宁愿避免它 这是我的档案: const CameraRender = (props) => { const [predictionLoaded, isPredictionLoaded] = useState(false); const [showModal, change

我正在尝试拍摄一张照片,当照片在后台返回其预测时,更新状态。但是,我无法让函数传入,它只是作为未定义的函数出现。我知道redux可能是最好的解决方案,但这是整个应用程序中唯一一个我有问题的状态,所以如果可能的话,我宁愿避免它

这是我的档案:

const CameraRender = (props) => {
  const [predictionLoaded, isPredictionLoaded] = useState(false);
  const [showModal, changeModalVisability] = useState(false);
  const [proportions, setProportions] = useState([]);
  const { setCameraInactive } = props;

  return(
    <View style={styles.container}>
      <Camera
        style={styles.container}
        ref={ref => {
          this.camera = ref;
        }}
      >
        <View style={styles.rectangle} />
        <View style={styles.pictureButton}>
          <Ionicons
            name='ios-camera'
            size={60}
            color={'#cdd2c9'}
            onPress={() => pictureHandler(this.camera, isPredictionLoaded(true),
                                          changeModalVisability(true), ((p1, p2) =>
                                          setProportions([p1, p2])))}
          />
        </View>
      </Camera>
      {showModal &&
        <PostPicModal
          predictionLoaded
          proportions
          setCameraInactive={() => setCameraInactive()}
          changeModalVisability={() => changeModalVisability(false)}
        />
      }
    </View>
  );
}

const pictureHandler = async (camera, addPic, isPredictionLoaded,
                              changeModalVisability, setProportions) => {
  const photo = await this.camera.takePictureAsync({ onPictureSaved: this.camera.pausePreview()});
  changeModalVisability();
  const prediction = await requestPrediction(photo.uri);
  setProportions(prediction[0][0], prediction[0][1]); //THIS ISNT WORKING
  isPredictionLoaded();
}
const-CameraRender=(道具)=>{
const[predictionLoaded,isPredictionLoaded]=useState(false);
const[showModal,changemodalvability]=使用状态(false);
常量[比例,设置比例]=useState([]);
const{setCameraInactive}=props;
返回(
{
this.camera=ref;
}}
>
pictureHandler(此摄像头,已加载预测(true),
可更改性(真),((p1,p2)=>
集合比例([p1,p2])}
/>
{showmodel&&
setCameraInactive()}
changeModalVisability={()=>changeModalVisability(false)}
/>
}
);
}
常量pictureHandler=async(摄像头、addPic、iPredictionLoaded、,
可更改性,设置比例)=>{
const photo=wait this.camera.takePictureAsync({onPictureSaved:this.camera.pausePreview()});
可更改性();
const prediction=wait requestPrediction(photo.uri);
设置比例(预测[0][0],预测[0][1]);//这不起作用
isPredictionLoaded();
}

我知道,当我将它传递给另一个功能组件时,这很容易,但我真的只想拥有一个可以接受状态的helper函数。我是不是应该把图片处理程序移到印刷机上?感谢您的帮助。

问题在于参数传递

您正在传递4个参数,但在函数中预期有5个参数

我认为调用函数时,
addPic
缺少参数

我也可以看到传递参数的问题,它应该是
isPredictionLoaded
,在函数内部,您可以使用true或false调用它,比如
isPredictionLoaded(true)