Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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
Reactjs TypeError:undefined不是对象(计算';_ref.painLevelColor';)_Reactjs_React Native_Metro Bundler - Fatal编程技术网

Reactjs TypeError:undefined不是对象(计算';_ref.painLevelColor';)

Reactjs TypeError:undefined不是对象(计算';_ref.painLevelColor';),reactjs,react-native,metro-bundler,Reactjs,React Native,Metro Bundler,我在react native中有一个功能组件,它作为道具接收其父状态 const PainLevel = ({painLevelColor = 'green', setPainLevelColor}) => {...} 家长: const BodyParts = () => { const [side, setSide] = useState('Front'); const [painLevelColor, setPainLevelColor] = useState('#4

我在react native中有一个功能组件,它作为道具接收其父状态

const PainLevel = ({painLevelColor = 'green', setPainLevelColor}) => {...}
家长:

const BodyParts = () => {
  const [side, setSide] = useState('Front');
  const [painLevelColor, setPainLevelColor] = useState('#43BA08');
return(
      {...}
      <PainLevel
        painLevelColor={painLevelColor}
        setPainLevelColor={setPainLevelColor}
      />
  );
};
const BodyParts=()=>{
const[side,setSide]=useState('Front');
const[painLevelColor,setPainLevelColor]=useState(“#43BA08”);
返回(
{...}
);
};
当两者都在同一个文件中时,它工作正常,但当我将我的子组件移动到我的组件文件夹中时,它会抛出此错误
TypeError:undefined不是一个对象(计算'\u ref.painLevelColor')

我还没有确定该项目的基础,也不知道是什么原因导致了这一点


有什么想法吗?

您应该提供子实体的更多信息、导入和内容

但是从您描述的错误和情况来看,我想您应该具有循环依赖性。您可能在彼此中使用了父级和子级,这会导致导入的值未定义。当它们在同一个文件中时不会发生这种情况

您可以在此处阅读更多有关循环依赖关系和解决方法的信息:


您能在使用子组件的地方添加代码,以及访问该道具的代码吗?谢谢添加。PainLevel中的代码在访问道具的地方是什么样子的?这有关系吗?我只是在一个单独的文件中移动了组件,并得到了错误