This document serves as a coding style guide to promote consistency in the code.
Functional Component style over Classes Typescript over Prop Types
The overall structure of this document draws from the Airbnb React Style Guide.
- Basics
- GraphQL Queries
- Class vs Functional Components
- Ordering
- Naming
- Props
- Files
- Methods
- Quotes
- Tests
- Console use
GraphQL queries (I.E. useStaticQuery
, query
) will be in a dedicated files that export one and only one query.
Naming of query should correlate with the queried data (source).
FDG uses functional components over classes.
FDG uses functional components over classes. Ordering for components
useState
or other custom hooks- local/
private
variables - local/
private
functions useEffect
- component
return
Following Airbnb style guide for Naming
New components should be written in Typescript.
Types
should be placed in the fdg-types.ts
file.
interface
s should be in separate files and located in src/models
.
Styles and unit test files will be in the same directory as their corresponding component.
Interface and type files that will/may be used by multiple components should be in the models
folder.
src/page-sections
folder for all page-sections used throughout the site.
Bind event handlers for the render method in the constructor.
Always use double quotes ("
) for JSX attributes, but single quotes ('
) for all other JS.
When needed, use data-testid
to when testing.
This allows for the use of
getByTestId
in the React Testing Library.
Newly written tests should make use of the React Testing Library. When advantageous, unit tests not using the React Testing Library should be refactored to do so.
Use of console.log
should only being used while debugging code in progress or
troubleshooting. For console
calls that will remain in the code, use console.info
,
console.warn
, or console.error
as appropriate.