Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlatList requires string as key #19237

Closed
James2516 opened this issue May 12, 2018 · 5 comments
Closed

FlatList requires string as key #19237

James2516 opened this issue May 12, 2018 · 5 comments
Labels
Component: FlatList Resolution: Locked This issue was locked by the bot. Type: Discussion Long running discussion.

Comments

@James2516
Copy link

James2516 commented May 12, 2018

Environment

Environment:
OS: macOS Sierra 10.12.6
Node: 9.8

Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.2 => 0.55.2

Expected Behavior

In a recent update, FlatList API is changed to require strings as keys.

Why is this breaking change implemented?
Many apps use an unique number id (eg. user id, item id) as the key.
Shouldn't any necessary casting be done internally within RN rather than requiring apps to do it?

The API change also makes the key requirement in FlatList inconsistent (more stringent) with keys used in array of components produced by map etc.

@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like your issue may be missing some necessary information. Can you run react-native info and edit your issue to include these results under the Environment section?

Thank you for your contributions.

@James2516

This comment has been minimized.

@aniltonveiga

This comment has been minimized.

@hramos
Copy link
Contributor

hramos commented Jan 29, 2019

The reasoning behind this has been covered in #18291. In short, using an index as a key is an anti-pattern. I don't think changing this back is something that would be considered.

@hramos hramos closed this as completed Jan 29, 2019
@James2516
Copy link
Author

James2516 commented Jan 29, 2019

@hramos but I'm not using index as key, I'm using unique item integer id (from database) which is the correct way.

@facebook facebook locked as resolved and limited conversation to collaborators Jan 29, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jan 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: FlatList Resolution: Locked This issue was locked by the bot. Type: Discussion Long running discussion.
Projects
None yet
Development

No branches or pull requests

4 participants