Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renderCell might not be necessary #27

Open
oliverjam opened this issue May 25, 2018 · 0 comments
Open

renderCell might not be necessary #27

oliverjam opened this issue May 25, 2018 · 0 comments
Assignees

Comments

@oliverjam
Copy link

Extracting part of your render into a function can be useful if you've got a huge render method that's gotten confusing, but in this case your renderCell() function just returns a React component. Since a component is effectively already a function you might as well skip the middleman and use it directly:

It's also probably more readable to extract a big render into an actual component rather than a normal function, since it'll fit in better with the rest of the JSX:

const CellList = ({ i } ) => (
<Cell
  className={`cell${i}`}
  value={this.state.cells[i]}
  onClick={() => this.handleClick(i)}
  style = {{backgroundColor: this.state.colours[i]}}
/>
)

This whole thing would probably be solved by using array.map((value, i) => <Cell ... />) though since it would make your render method a lot smaller.

@isnotafunction isnotafunction self-assigned this May 25, 2018
isnotafunction added a commit that referenced this issue May 25, 2018
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

No branches or pull requests

2 participants