question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Getting a Warning: Each child in a list should have a unique "key" prop. error when using this library inside a React Typescript application.

To reproduce:

  • Inside a react with typescript app, initialize GooglePlacesAutocomplete with most basic configurations
  • Start typing the ABCs, around 5-10 characters, this warning floods the console.

I probably could fix it and make a PR, but I thought I should submit the issue first.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bencehornakcommented, Jul 22, 2020

I think the problem is on Google’s side. Sometimes their API omits the id from the returning JSON for no reason 😬

For example, I intercepted this URL in the DevConsole:

https://maps.googleapis.com/maps/api/place/js/AutocompletionService.GetPredictionsJson?1sab&4sde-DE&7scountry%3AHU&9saddress&15e3&21m1&2e1&callback=_xdc_._8umyg&key=<My API KEY>&token=93086

If I fetch it repeatedly, sometimes id is included, sometimes it’s not 😒

Good response:

/**/_xdc_._8umyg && _xdc_._8umyg( {
   "predictions" : [
      {
         "description" : "Budapest, Abonyi utca, Ungarn",
         "id" : "5695d25a61ef2c2d780f2ae58e71fdde88c1c643", // here we have the id
         "matched_substrings" : [
            {
               "length" : 2,
               "offset" : 10
            }
         ],
         "place_id" : "Eh1CdWRhcGVzdCwgQWJvbnlpIHV0Y2EsIFVuZ2FybiIuKiwKFAoSCcNfVy6H3EFHEZVUoNFY40HvEhQKEgnJz9TRNMNBRxFgER4MKcQABA",
         "reference" : "Eh1CdWRhcGVzdCwgQWJvbnlpIHV0Y2EsIFVuZ2FybiIuKiwKFAoSCcNfVy6H3EFHEZVUoNFY40HvEhQKEgnJz9TRNMNBRxFgER4MKcQABA",
         "structured_formatting" : {
            "main_text" : "Abonyi utca",
            "main_text_matched_substrings" : [
               {
                  "length" : 2,
                  "offset" : 0
               }
            ],
            "secondary_text" : "Budapest, Ungarn"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Budapest"
            },
            {
               "offset" : 10,
               "value" : "Abonyi utca"
            },
            {
               "offset" : 23,
               "value" : "Ungarn"
            }
         ],
         "types" : [ "route", "geocode" ]
      },
...

Bad one:

/**/_xdc_._8umyg && _xdc_._8umyg( {
   "predictions" : [
      {
         "description" : "Budapest, Abonyi utca, Ungarn", // id is missing !!!!!!!!!
         "matched_substrings" : [
            {
               "length" : 2,
               "offset" : 10
            }
         ],
         "place_id" : "Eh1CdWRhcGVzdCwgQWJvbnlpIHV0Y2EsIFVuZ2FybiIuKiwKFAoSCcNfVy6H3EFHEZVUoNFY40HvEhQKEgnJz9TRNMNBRxFgER4MKcQABA",
         "reference" : "Eh1CdWRhcGVzdCwgQWJvbnlpIHV0Y2EsIFVuZ2FybiIuKiwKFAoSCcNfVy6H3EFHEZVUoNFY40HvEhQKEgnJz9TRNMNBRxFgER4MKcQABA",
         "structured_formatting" : {
            "main_text" : "Abonyi utca",
            "main_text_matched_substrings" : [
               {
                  "length" : 2,
                  "offset" : 0
               }
            ],
            "secondary_text" : "Budapest, Ungarn"
         },
         "terms" : [
            {
               "offset" : 0,
               "value" : "Budapest"
            },
            {
               "offset" : 10,
               "value" : "Abonyi utca"
            },
            {
               "offset" : 23,
               "value" : "Ungarn"
            }
         ],
         "types" : [ "route", "geocode" ]
      },
...
1reaction
lslee714commented, Jul 8, 2020

Yeah it’s weird, the error only happens once and after it happens, it doesn’t complain again. I’ll take a look sometime in the near future haha

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: Each Child in a List Should Have a Unique 'key' Prop
When creating a list in the UI from an array with JSX, you should add a key prop to each child and to...
Read more >
Understanding unique keys for array children in React.js
Each child in an array should have a unique "key" prop. However, in many cases it is not! This is anti-pattern that can...
Read more >
How to Fix 'Each child should have a unique key prop' - Webtips
The "Each child in a list should have a unique "key" prop." warning happens in React when you create a list of elements...
Read more >
Each child in a list should have a unique "key" prop in react js ...
How to solve Warning : Each child in a list should have a unique " key" prop in react js is shown.
Read more >
[SOLVED] Each child in a list should have a unique "key" prop ...
Hello today in this video i'm going to show how to fix this warning, that may cause you some problems later when you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found