| Conditions | 2 |
| Total Lines | 56 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import React, { Component } from 'react' |
||
| 17 | |||
| 18 | render() { |
||
| 19 | const { |
||
| 20 | userList, |
||
| 21 | userDetail, |
||
| 22 | something, |
||
| 23 | } = this.props |
||
| 24 | |||
| 25 | return ( |
||
| 26 | <div className="App"> |
||
| 27 | <div className="block"> |
||
| 28 | <h1>UserList</h1> |
||
| 29 | |||
| 30 | {userList.loading && <div>Loading...</div>} |
||
| 31 | {!!userList.value && userList.value.map((user, i) => ( |
||
| 32 | <div key={user.id}> |
||
| 33 | {i + 1}. {user.first_name} {user.last_name} |
||
| 34 | </div> |
||
| 35 | ))} |
||
| 36 | </div> |
||
| 37 | |||
| 38 | <div className="block"> |
||
| 39 | |||
| 40 | <h1 className="App-title">UserDetail</h1> |
||
| 41 | {userDetail.loading && <div>Loading...</div>} |
||
| 42 | {!!userDetail.value && ( |
||
| 43 | <div> |
||
| 44 | ID: {userDetail.value.id}<br /> |
||
| 45 | First name: {userDetail.value.first_name}<br /> |
||
| 46 | Last name: {userDetail.value.last_name} |
||
| 47 | </div> |
||
| 48 | )} |
||
| 49 | </div> |
||
| 50 | |||
| 51 | |||
| 52 | <div className="block"> |
||
| 53 | <h1 className="App-title">Something</h1> |
||
| 54 | {something ? ( |
||
| 55 | <div> |
||
| 56 | {something[2] && something[2].loading && <div>Loading...</div>} |
||
| 57 | {something[2] && something[2].value && |
||
| 58 | <div>{something[2].value.name}</div>} |
||
| 59 | {something[5] && something[5].loading && <div>Loading...</div>} |
||
| 60 | {something[5] && something[5].value && |
||
| 61 | <div>{something[5].value.name}</div>} |
||
| 62 | </div> |
||
| 63 | ) : ''} |
||
| 64 | </div> |
||
| 65 | |||
| 66 | <a |
||
| 67 | href="https://github.com/expert-m/redux-class-decorators/tree/master/examples/simple" |
||
| 68 | target="_blank" |
||
| 69 | rel="noopener noreferrer" |
||
| 70 | className="link" |
||
| 71 | >GitHub</a> |
||
| 72 | </div> |
||
| 73 | ) |
||
| 99 |