Skip to content

Destructuring props in functional components #32

@Oliversw

Description

@Oliversw

Just a useful tip - you can destructure props in your components so that you can access them directly as variables, instead of always with props.myVariable

For example on your landing page when you're declaring your component like this:
const LandingPage = props => {
You need to access your props like this:
props.setGameData()

You could change that to:
const LandingPage =({ setGameData, userData, setUserData }) => {
So that you can access them like:
setGameData()

It's a small change, but definitely makes things easier for me. It's also nice because you can tell at a glance at your functional component what props you are expecting it to have :)

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