This document includes codebase contentions and style guidelines for Spoke, especially those that are not captured by prettier nor eslint.
-
Component Props a. Props interface naming should follow this convention:
[ComponentName]Props
. b. Type definition for component props should be exported. -
Variable Names a. Use affirmative variables for component behavior, i.e.
showWarning
rather thanhideWarning
. -
Do not render unnecessary
div
s as they make it slower for the browser to render the page. When needed, returnnull
instead of an emptydiv
. -
Use
graphql-codegen
and import GraphQL types from@spoke/spoke-codegen
when appropriate. -
When working with old class type components, which might be bad candidates for immediate refactoring, refactor the GraphQL queries to import
QueryDocument
from@spoke/spoke-codegen
.
-
Constrain inline CSS to a single style at most. If more than that, use a
makeStyle
hook. -
Use
theme.palette
colors over direct definitions of colors. If a direct definition is required, import and use the color from@material-ui/core/colors
.
- GraphQL Errors a. If data is erroneouly fetched for display, render an inline list of errors using a MUI component. b. If the operation eliciting an error is performed from a button, render a modal with an error. c. If the operation eliciting an error is performed within a modal, render an inline error at the top of the modal.