PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 27, 2022

[FIXED] Where is this coming from: Warning: Each child in a list should have a unique "key" prop

 April 27, 2022     dictionary, reactjs, unique-key, warnings     No comments   

Issue

I try this CodeSandbox and also tried it in VCode locally but can't see where this warning in the log comes from:

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

Check the render method of `App`. See https://reactjs.org/link/warning-keys for more information.
    at CurrentForm (http://localhost:3000/static/js/main.chunk.js:1284:11)
    at App (http://localhost:3000/static/js/main.chunk.js:1102:70)

I changed the CurrentForm Component "Form.js" map so the key had a unique id using like "npm i uuid" but that was not it.


Solution

Add key to Form component: Codesandbox

import React, { useReducer } from "react";
import ReactDOM from "react-dom";
import { Router } from "@reach/router";
import { Form, Result, Landing } from "./steps";
import { NavigationButtons } from "./components";
import { initialState, dataReducer, DataContext } from "./dataContext";
import { formConfig } from "./consts/formConfig";

import "./styles.css";

function App() {
  return (
    <div>
      <DataContext.Provider value={useReducer(dataReducer, initialState)}>
        <Router>
          <Landing path="/" />
          {formConfig.map(({ prevStep, ...props }, index) => (
            <Form
              key={index}
              {...props}
              render={(prevStep) => <NavigationButtons prevStep={prevStep} />}
            />
          ))}
          <Result path="result" />
        </Router>
      </DataContext.Provider>
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);


Answered By - Ketan Ramteke
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing