Skip to content

Barney commentary#4

Open
barneycarroll wants to merge 3 commits into
btomy:masterfrom
barneycarroll:barney-commentary
Open

Barney commentary#4
barneycarroll wants to merge 3 commits into
btomy:masterfrom
barneycarroll:barney-commentary

Conversation

@barneycarroll
Copy link
Copy Markdown

Just putting this up here as a kind of dynamic code review

@barneycarroll
Copy link
Copy Markdown
Author

BTW when looking at a commit or a pull request's diff, append ?w=1 to the query string to hide whitespace changes

class Answer extends React.Component{
constructor(props) {
super(props);
const Answer = props => (
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Where possible, functional components are IMO better because you get an immediate assurance that there is no lifecycle and no state, which makes it easier to reason about contents.

Un-bracketed arrow functions are even better because they are 'point-free', ie there are no internal references, just a return expression. Previously there were 2 points: declare a variable to define the options, then return a block of content which references the options. I prefer this because it's less moving parts to remember – some people dislike it on the grounds it encourages that any logic (ie the options.map) gets put in the content (I don't see a problem with that 🤷‍♂️ ).

name='rad'
id={`option_${i}`}
onChange={() => {
props.handleRadio(i)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I prefer using anonymous event handlers in the view and calling function references within that – this avoids the necessity of re-binding class methods elsewhere because we explicitly avoid the this re-binding that comes from event handler assignment. Previously, the parent component's this binding for handleRadio was over-written by the binding here.

type="submit"
className='waves-effect waves-light btn-large submit-button visible'
onClick={props.onClickCallback}
disabled={!props.selectionMade}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Boolean attribute expressions can be expressed like this – I love it.

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.

1 participant