george-haddad / tool-belt

GNU Lesser General Public License v3.0
1 stars 0 forks source link

Use class property syntax to initialize component state #16

Open zacharygolba opened 6 years ago

zacharygolba commented 6 years ago

It looks like your already taking advantage of a babel preset that enables class fields proposal. The same trick used to bind this to a component classes' event handlers can be used to initialize state!

For example:

https://github.com/george-haddad/tool-belt/blob/07632d25e2df3c277fd0cb18459f110bbbb8a1bd/src/components/axfr-check/index.jsx#L29-L39

Can be simplified to:

class AxfrOnlineCheck extends Component<Props, State> { 
  state = { 
    loading: false, 
    axfrStatus: 'start', 
    domain: '', 
    affectedDns: undefined, 
    error: false, 
  };
} 
george-haddad commented 6 years ago

Thanks for that tip, after reading your explanation it made sense. Sometimes I just use babel presets without knowing what they really do, but do it because it's been ingrained through hours of tutorials and articles you read.