score:9
in your productlist component you are using a promise instead of rendering child, to overcome this you can make it a stateful component fix this like:
import react, { component } from 'react';
import product from "./product/index";
class productlist extends component {
constructor(props) {
super(props)
this.state = {
goods: []
}
}
componentdidmount = () => {
import("../../../data/data.json")
.then(json => this.state({ goods: json.goods }))
}
render() {
const { goods } = this.state
return (
<div>
{goods.map(image => <div><product images={image.pictures} /></div>)}
</div>
)
}
}
export default productlist;
or alternatively you can import it in beginning like:
import react from 'react';
import product from "./product/index";
import goods from "../../../data/data.json"
const productlist = () => {
const renderedgoods = goods.map(image => {
return <div><product images={image.pictures} /></div>
})
return <div>{renderedgoods}</div>
}
export default productlist;
not an issue, yes you resolved the promise correct,
but as even when you type in console what you are actually returning is a promise and .then or .catch are callbacks called when its either resolved or rejected so you see react wants is something to render and you cannot render a promise
score:1
close - move the import to the top of file:
import mydata from "../../../data/data.json";
then change your rendered list to this:
const renderedlist = mydata.goods.map(image => (<div><product images={image.pictures} /></div>));
score:2
it works but why you are importing json data use axios insted of import. axios documentation
your component will look like
import react, { component } from 'react';
import axios from 'axios';
import product from "./product/index";
class productlist extends component {
constructor(props) {
super(props)
this.state = {
products: []
}
}
componentdidmount = () => {
axios.get("products.json").then(json => {
this.setstate({ products: json.data.goods });
});
}
render() {
const { products } = this.state
return (
<div>
{products.map(image => <div><product images={image.pictures} /></div>)}
</div>
)
}
}
export default productlist;
keep your json or data file inside public folder
i hope this works for you
score:2
just use map
or filter function as the array
you are trying to render is an array of objects and those objects can't be rendered due to multiple re-rendering and hence react dom won't allow that .
Source: stackoverflow.com
Related Query
- Objects are not valid as a React child (found: object with keys {username}). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {name}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {job}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {totalItems}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {arr}). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead. JS
- Objects are not valid as a React child (found: object with keys {weight}). If you meant to render a collection of children, use an array instead
- React: Objects are not valid as a React child (found: object with keys. If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with keys {name}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {children}). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with keys {value}). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with key. If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {items}). If you meant to render a collection of children, use an array instead
- My error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead
- How to fix Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {})/If you meant to render a collection of children, use an array instead. Help me?
- Uncaught Error: Objects are not valid as a React child (found: object with keys {todo}). If you meant to render a collection of children, use an array
- Objects are not valid as a React child (found: object with keys {id, name}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys} If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: [object Element]). If you meant to render a collection of children, use an array instead.- ReactJs
- Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead. ReactJS
- react matrerial ui Error: Objects are not valid as a React child If you meant to render a collection of children, use an array instead
- ×Objects are not valid as a React child (found: object with keys {author, quote}). If you meant to render a collection of children, use an array
- Objects are not valid as a React child If you meant to render a collection of children, use an array instead
- REact error Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child . If you meant to render a collection of children, use an array instead
More Query from same tag
- Passing a value back to the parent from a form
- Antd select not working inside a full screen dialog
- Folder structure for React and Django REST
- align items in a form at center
- plz help for aws ec2 react+node build error
- How to call a function in a local function
- How to fix lag on select element containing a large list of options
- Google Tag Manager hangs on XHR Ready State Changed
- How to add a route to image in React.js
- prevent multiple form submissions in reactjs
- Inject properties into child components in React
- React app freezes after running npm start . The issue is observed while compilation
- net::ERR_INVALID_URL when setting <img> src from base64 string
- Audio tag keeps loading when music is paused
- Error: Failed to load parser 'babel-eslint' declared in '.eslintrc': Cannot find module 'babel-eslint' in create-react-app
- UPI payment showing error "For security reasons, you are not allowed to send money from your bank account for this payment." in PhonePe
- How to remake and export/import function in React?
- Why does my React Dom render method not work?
- Router link giving warning " link is a void element tag and must not have `children` or use `props.dangerouslySetInnerHTML`."
- How to resolve infinite loop error in reactjs?
- How can I render an Array nested in another Array with React
- ReactNative App issue in the store
- Antd Select not setting initial value
- React useState rerender trigger behaves different depending of when its called
- Remove Items dynamically from Array of Objects
- How to remove spaces onPaste in reactjs
- Running Npm install outside client folder is causing corruption?
- React: setting state in container from within functional component
- Show/Hide Based on Button State
- Ternary expression with multiple conditions