簡體   English   中英

React Native,錯誤:對象作為 React 子項無效

[英]React Native, Error: Objects are not valid as a React child

我將道具傳遞給不同的組件,因此我可以進行 api 調用。 它使 api 調用,我可以 console.log 罰款,但不會渲染屏幕,我得到這個錯誤:

"Error: Objects are not valid as a React child (found: object with keys {_U, _V, _W, _X}). If you meant to render a collection of children, use an array instead."

代碼:

const BlogScreen = route => {
  const blog_id = route.route.params.blog_id;

  return (
    <SafeAreaView style={styles.screen}>
      <Header />
      <BlogDetails blog_id={blog_id} />
    </SafeAreaView>
  );
};



export default BlogDetails = async props => {
  const blog_id = props.blog_id;
  console.log(blog_id);
    await axios
      .get(url)
      .then(res => {
          console.log(res.data);
       });
  return (
    <View style={{width: '100%', flex: 1}}>
      <Text></Text>
    </View>
  );
};

BlogDetails組件似乎不正確。

這是一個解決方案:


export default BlogDetails = props => {
  const blog_id = props.blog_id;
  console.log(blog_id);

  useEffect(() => {
    axios
      .get(url)
      .then(res => {
          console.log(res.data);
       });  
  },[])
  
  return (
    <View style={{width: '100%', flex: 1}}>
      <Text></Text>
    </View>
  );
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM