首页 > 解决方案 > React Native 与 expo 错误:useEffect 只读

问题描述

我尝试了两个步骤,我得到了同样的错误(useEffect read-only):

const  requestPermission = async ()=> {
    const {granted}= await ImagePicker.requestCameraRollPermissionsAsync;
    if(!granted) 
     alert('You have to enable permission to access photos');
  };

useEffect =(()=> {
 requestPermission();
},[]) 

第二种方法是

useEffect =(()=> {
 const request = async ()=>{
  const {granted}= await ImagePicker.requestCameraRollPermissionsAsync;
  if(!granted)
  alert('You have to enable permission to access photos');
 };
},[])

先感谢您。

标签: react-nativeexpohook

解决方案


您的通话中有一个=标志(就在 之后),这使得您看起来像是在分配某些东西useEffectuseEffectuseEffect

编辑:

useEffect(() => {
  requestPermission();
}, [])

您必须以相同的方式编辑您的其他呼叫。


推荐阅读