score:3
Accepted answer
While there shouldn't be 2 blogs with the same ID you can fix the issue at hand by replacing the key from blog.id
to the index
of the post like this.
<div>
<h2>Blogs</h2>
<p>{user.name} logged in</p>
{logout()}
//change
{blogs.map((blog,index) =>
<Blog
//change
key={index}
deleteBlog={() => deleteBlogId(blog.id)}
blog={blog}
increment={() => incrementLike(blog.id)} />
)}
</div>
I added //change
to the lines I changed.
score:2
You can just use something like uuid for this which will generate a unique ID.
import uuid from "uuid";
<>
<h2>Blogs</h2>
<p>{user.name} logged in</p>
{logout()}
{blogs.map((blog,index) =>
<Blog
key={uuid.v4()}
deleteBlog={() => deleteBlogId(blog.id)}
blog={blog}
increment={() => incrementLike(blog.id)} />
)}
</>
Source: stackoverflow.com
Related Query
- Duplicate keys in React, can't solve the issue. Encountered two children with the same key
- Encountered two children with the same key, `1`. Keys should be unique so that components maintain their identity across updates. Laravel React JS
- React Warning: flattenChildren(...): Encountered two children with the same key
- Warning: flattenChildren(...): Encountered two children with the same key / Child keys must be unique
- React Warning: flattenChildren(...): Encountered two children with the same key, `.${index}`
- React "Warning: Encountered two children with the same key"
- How to fix 'flattenChildren(...): Encountered two children with the same key' with React and Semantic UI
- Encountered two children with the same key in React
- Warning: Encountered two children with the same key when implementing a Search Filter in React
- Warning: flattenChildren(...): Encountered two children with the same key in React Mobx Component
- Warning: Encountered two children with the same key for react infinite scroll
- Two children with the same key in React
- React Infinite Scroller - Two children with the same key. loadMore function being called twice
- Warning: Encountered two children with the same key, `[object Object]`
- React: Encountered two children with the same key
- How can I resolve "Warning: Encountered two children with the same key" on React.js
- Encountered two children with the same key Error
- Encountered two children with the same key
- index.js:1 Warning: Encountered two children with the same key, `index`. Index is unique
- Warning: flattenChildren(...): Encountered two children with the same key
- What can i pass in as placeholder for first argument in map function Warning: Encountered two children with the same key, `[object Object]`
- ReactJS Warning: Encountered two children with the same key after changing components
- Encountered two children with the same key error on Material-UI with React; it keeps re-rendering Collapse every time drawer is opened
- warning.js:45 Warning: flattenChildren(...): Encountered two children with the same key, `.1:$..`
- Two children with the same key in React component
- Warning: flattenChildren(...): Encountered two children with the same key in reactjs
- Warning: Encountered two children with the same key, `0`
- Warning: Encountered two children with the same key, `[object Object]
- React: flattenChildren(...): Encountered two children with the same key
- useState creates duplicates - infinite scrolling - Warning: Encountered two children with the same key
More Query from same tag
- Display Alerts and Remove it using States
- How to combine multiple classNames in React?
- Programmatically close Material-UI Autocomplete popper results
- Can I host the same react app at two different paths on my website?
- Express, how to pass long url path to react router?
- Trying to load multiple C3 charts in same react component
- mapStateToProps doesn't change state
- How can I use input type='text' in a Icon Button (Material UI) in React?
- how to secure security_access_key in react js application?
- how to map through multiple images, after connecting to a third party api
- Material UI v5 Different Primary Color Based on Mode (Light/Dark)
- React Router v4 components with similar paths (fixed and dynamic path param) are "overlapping"
- How to set initialValue for dynamic form field (ant design)?
- show/hide a specific <div> in react
- ElevationScroll 'children' prop expects a single child of type 'ReactElement<any, string
- Not getting data from nodejs server for the first time in React
- Dynamically render a sequence of divs
- Emotion's CSS props not working with Create-React-App
- Make a card component as drawer Ant Design
- React, Leaflet - Hooks, setView, and useRef
- Listen to Formik values changes
- How to trigger anchor tag :target action even at same position?
- StencilJS error with React output target - You may need an additional loader to handle the result of these loaders
- Polygons in google maps heatmap layer
- Redux Authentication not using updated props?
- Can I make a React component re-render itself when it's attribute is a reactive data source from Meteor?
- Difference between this ES6 arrow function and regular function?
- Middle URL Parameter in React Router
- How to correctly setup a conditional expression (if) in a React render()
- How to apply horizontal scrolling in multiple div on a single button click?