fac18 / nikkin-react-game

See the project here:
https://nikkin-react-game.netlify.com/
0 stars 1 forks source link

Destructuring props in functional components #32

Open Oliversw opened 4 years ago

Oliversw commented 4 years ago

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 :)

Oliversw commented 4 years ago

I see you've actually done this in player.js!