0

I am having the array of data which is rendered using map in React Native.But the component is rendering the data twice throwing the exception

Warning: Each child in a list should have a unique "key" prop.

Here is my code.

  const test = ["Test1","Test2","Test3" ]
<View>
 {test.map(item=><Text>{item}</Text> )}
</View>
1
  • If i understand correctly, your data is showing up twice? Can you show more relevant code. Also this is just a warning which can be fixed using a unique key. Commented Sep 21, 2021 at 9:37

1 Answer 1

1

Warning: Each child in a list should have a unique "key" prop.

As it says ... It's just a warning

That can be fixed adding some unique key to your <Text>

const test = ["Test1", "Test2", "Test3"];
<View>
  {test.map((item, index) => <Text key={index}>{item}</Text> )}
</View>

Worth to mention that using index as key is anti-pattern in certain use cases.

With the sample you gave us, the data should only be printed once

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.