I am just starting with ReactJS and tried solutions of other questions similar to this but no luck so far.
Here is my working code :
import React from 'react'; import ReactDOM from 'react-dom'; const Numbers = ['2', '4', '6', '8']; const NumbersList = (props) => ( <ul> { props.Numbers.map ( number => <li key={number}>{number * 2}</li> ) } </ul> ) ReactDOM.render(<NumbersList Numbers = {Numbers} />, document.getElementById('root') ) But when I am passing Numbers Array as :
const Numbers = ['4', '4', '6', '8'] I am getting this error :
Warning: Encountered two children with the same key, 4. Keys should be unique so that components maintain their identity across updates.
So my Question is : What is the best way to give keys in this situation? And if I am using Number (as in above example) as Keys, what is the best solution to avoid this warning?
Thank You!