Skip to content

Conversation

@OriLev
Copy link
Owner

@OriLev OriLev commented Jan 10, 2018

No description provided.

@OriLev OriLev merged commit 54341d9 into master Jan 10, 2018
disabled = {disabled}
key = {'button' + index}
className = {classes}
style = {buttonHeight.style}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cleaner way to express props:

const { style, } = buttonHeight
const buttonProps = {
  type: 'button',
  disabled,
  key: index,
  className: classes,
  style,
  onClick,
  children: text,
}
return <Button {...buttonProps} />

This is better in several ways:

  1. Instead of using the ugly JSX key={{value}} verbose syntax, you use objects/classes/functions - with the full expressivity of the JS language
  2. You separate props (in essence, they are function arguments) from the component structure, so you see your component tree at a glance.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. mind blown. so simple and somehow haven't crossed my mind so far.

  2. about the key - you used key: index, which raised a question in my mind: I tried giving unique keys to all my elements that were constructed via map(), hence the combination of 'button' + index, unlike 'cell' + y + x. Does the fact that you used only index in your example mean that I can keep the keys not unique BETWEEN different maps?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. it's not that obvious. Did you read the react docs and official tutorial? ALL the docs?
  2. https://reactjs.org/docs/lists-and-keys.html#keys

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading now...

It's quite a lot, so I will be making some progress with the code cleanup as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants