GithubHelp home page GithubHelp logo

react-spot-the-mistake's Introduction

react

React Spot The Mistake


I post <Spot the mistake in #react code> on my Linkedin, which I'll also post here!

From basic to advanced: test how well you know React, refresh your knowledge a bit or prepare for your coding interview! ๐Ÿ’ช ๐Ÿš€ I update this repo regularly with new questions. I added the best answer and the linkedin profile of the person who answered it in the collapsed sections below the questions, simply click on them to expand it. It's just for fun, good luck! โค๏ธ



Best Answer

Using index as key when mapping and returning elements in React it will cause errors in the future when you wish to update or delete one of them.

React usesindex in mapping so it can specify elements from each other. If you use index as keys, whenever you delete one of the elements, the indexes will be used wrongly for other elements, so it will cause unpredictable errors and bugs, especially whenever you are using third parties.

If your list wont be updated or modified, and it will be statics and constant so there is no problem using indexes as keys but it's always a best practice to use unique keys.

If you dont have already some kind of databse ids or any uniqe identifiers you can use libraries that generate uniqe ids such as uuid and be sure the will be no errors or bugs.

And there is no error for returning an array of elements in a React component You are allowed to return an array (an array of any type) as output in your React component.


Best Answer

โŒ laptopsList: will be treated as a built-in DOM element.

โœ… LaptopsList: All React component names must start with a capital letter.

Considering key values, REZAZI MOHAMED ABDESSAMED, i think using random values is a bad practice, because it will cause the item to re-mount on every render, but not really a "mistake" for such static list, imo. .

react-spot-the-mistake's People

Contributors

alamenai avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.