Skip to content

React Fragments: the miracle cure for div-itis! #46

@bobbysebolao

Description

@bobbysebolao

In case you don't know, React provides a component called Fragment that you can use in place of a div to group together JSX elements inside a return block. You can import it from React and use it exactly like you would use a div, the advantage is that it Fragments don't appear in the rendered HTML page (in other words, it doesn't clutter the web page with semantically meaningless divs) :

import React, { Fragment } from 'react'

export default ({ startGame, topScore, chooseCharacter, chooseDifficulty }) => {
  return (
    <Fragment>
       ...
       ...
       ...
       ...
       ...
    </Fragment>
  )
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions