When creating a component, there is a specific order to methods in order to quickly find what you're looking for.
- Constructor
- Lifecycle methods
- Event Handlers
- on{Subject}{Event}
- handle{Subject}{Event}
- Custom component methods
- Render methods
Event Callbacks
We split events into two groups. Server and User triggered events. Server events are prefixed with on
and User events are prefixed with handle
.
Examples:
onMarathonStoreChange
-MarathonStore
is the subject, whileChange
is the Event.onVisibilityChange
- Triggered when the browser tab becomes inactivehandleButtonClick
- Handles click on a buttonhandleImageHover
– Handles the user hovering an image
Render Methods
Typically when writing a #render
method which renders a few bits, split the different bits into smaller ones, always prefixed with get
.
Example:
class Foo {
...
render () {
return (
<div>
{this.getBarGraph()}
{this.getFilterBar()}
{this.getTable()}
</div>
);
}
}
We are trying to move away from mixins. Do not create mixins.
Things to alphabetize:
- Imports
- Variable declarations
- JSX props. Example:
return (
<Modal
className="modal modal-large"
closeByBackgroundClick={false}
open={true}
/>
);
- Keys in an object. Example:
this.state = {
disableSubmit: false,
openModal: false,
services: [],
};
API Requests should go into an Action file like this