• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: REACT JS How can I convert that to as a component?

Resolved: REACT JS How can I convert that to as a component?

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have a data for push to front with cards. I just found this way works with cards but I want to use Cards component for make it better.
If I convert innerHTML part to that:
I am getting as a output

[object Object][object Object][object Object][object Object]


Where I am making mistake? and how can I push to front this json data with cards?
Example json data

Answer:

Just remove the document.getElementById('cards').innerHTML +=. You don’t want that. ReactJS should do the DOM update. And, you should not return from the fetch function. Create a state, and you can use it to render the JSX.. Here is the properly structured Functional Component for you.
Here, I used the useEffect hook to fetch the items when the component is mounted on DOM. And we are verifying if the item object is not empty before rendering

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

javascript reactjs
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: The ‘Access-Control-Allow-Origin’ header contains multiple values ‘*, *’, but only one is allowed. cors error not resolving

02/04/2023

Resolved: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘crm.email’ doesn’t exist (Connection: mysql, SQL: select count(*) as aggregate from `email`

02/04/2023

Resolved: Regex: Curly braces in reverse? Match X characters before a string?

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

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