• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: ReactJS – Trying to access the title of an object I’m pulling from a webpage online, but getting these errors

Resolved: ReactJS – Trying to access the title of an object I’m pulling from a webpage online, but getting these errors

0
By Isaac Tonny on 15/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve ReactJS – Trying to access the title of an object I’m pulling from a webpage online, but getting these errors

Question:

I’m trying to create a news website with ReactJS and I’m getting three various warnings/errors when I try to run the page. I can get it to display the article link properly when I don’t include the title. I still get the two first warnings in this case, but when I try to access the article’s title it won’t load the page at all.
Any help is greatly appreciated.
The warnings/errors:
Warning: Each child in a list should have a unique “key” prop.
Warning: Invalid value for prop href on tag.
Uncaught Error: Objects are not valid as a React child (found: object with keys {rendered}). If you meant to render a collection of children, use an array instead.
LatestArticles.js
Article.js

Best Answer:

Warning: Each child in a list should have a unique “key” prop.
  • when adding keys you need to add it to the parent element of the item (in this case the ul tag).

Warning: Invalid value for prop href on tag.
Uncaught Error: Objects are not valid as a React child (found: object with keys {rendered}). If you meant to render a collection of children, use an array instead.
For these two errors, it might be due to how you are fetching your data, but there are a few things I would look into first:
  1. You are using react hooks within a React hook (useState and React.useState), instead make the default an empty array.



  1. Take your useEffect out of your function since it only runs when there are side effects… I would remove your function altogether and just stick to rendering your posts through the useEffect and that should work.

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

javascript jsx reactjs
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How can I copy files using the ansible.builtin.copy module and avoid conflicting file names?

26/03/2023

Resolved: Reshape tensors of unknown shape with tf.function

26/03/2023

Resolved: Use Svelte Component as Slot

26/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.