Comments (5)
Hii @Karim-Muhammad, can you please checkout this. https://codesandbox.io/s/falling-snow-2kn7hk?file=/src/App.js
That map of authors code is returning an array which is type of object.
So and as you can see in error
Objects can't be render as child.
from react.
@Karim-Muhammad I think I have solved your issue please check it out
https://codesandbox.io/s/dazzling-dust-tx2qwm?file=/src/App.js
from react.
That map of authors code is returning an array which is type of object.
the message error says use array
instead of object
, and i really return authors.map()
(array), so message error doesn't clarify the problem enough, actually it make confusion, that's my point
yeah, I know type of array is object, but we actually can render an Array(Object) in JSX in case it is child not parent to
<div> {array} </div> //Correct
that's OK, but if array
is a parent (without a container
return {array} // Wrong
it throw an Error (not meaningful message) says as I mentioned above "cannot render object" instead of "cannot have multiple root elements"
the Error message you have shown above, says what i did already in my code, i'm trying to render an Array, and avoid using "Object"
I don't know if you got my point, I apologize for any confusion.
from react.
Thanks for your time, I appreciate that
my point is that error message doesn't clarify my problem precisely
from react.
Based on the error message you provided, it seems that the issue lies in how you are rendering the postsList.jsx array in your PostsList component. The error suggests that you are trying to render an object instead of an array.
To resolve this issue, you need to wrap the postsList.jsx array in a parent element when returning it from the component. One way to achieve this is by using a React fragment (<>...</>) as suggested in the error message. Here's an updated version of your PostsList component:
import {useSelector } from "react-redux ; import { selectAllPosts } from '../../app/features/posts/slicer';
const PostsList = (props) => { const posts = useSelector(selectAllPosts); const postsListjsx = posts.map(post => ( <article key={post.id}> <h3>{post.title}</h3> <p>{post.content.substring(0, 100)}</p> </article> ));
return ( <> {postsListjsx} </> ); }
export default PostsList;
By wrapping the postsListjsx array in <>...</>, you create a parent element that contains the array elements. This allows you to return multiple elements without encountering the "Adjacent JSX elements must be wrapped in an enclosing tag" error.
After making this change, the error you mentioned should be resolved, and the PostsList component should render the list of posts correctly.
from react.
Related Issues (20)
- [DevTools Bug] Children cannot be added or removed during a reorder operation. HOT 1
- Bug: SetState with same value, rerenders one more time HOT 7
- [DevTools Bug]: TypeError: ie.handlePostCommitFiberRoot is not a function HOT 3
- Hey really.org
- Bug: Invalid options to hydrateRoot can error with "This root received an early update" HOT 1
- Bug: `Children.map` raises error when passed async server component within client component HOT 4
- Bug: mouse events are bubbled up too far with some pointer-events rules HOT 1
- Bug: Unsupported HTML character references HOT 6
- Bug: React not defined in TypeScript when importing from npm HOT 8
- After using forwardRef in a JSX component, you encounter an error when using it in a TSX component. HOT 1
- [DevTools Bug] Could not find node with id "464" in commit tree HOT 1
- ⚠Phishing Website Warning!!! There are phishing website links in the document. HOT 6
- not showing components in inspect its stuck
- [DevTools Bug]: I can't see the "Profiler" and "Components" in my dev tools HOT 1
- [DevTools Bug]: I can't see the "Profiler" and "Components" in my dev tools HOT 2
- Bug: Event handling with portals is broken
- Feature Request: useOnLoadEffect() -> empty dependency array useEffect wrapper
- Larger files upload rejection message instead of net::ERR_CONNECTION_RESET
- Bug: yo HOT 1
- Bug: refObj returned from useRef is not sealed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.