Component Structure
Overview
General
Location of layout and utility/reusable components: /src/components/
Location of page-related components: /src/pages/[page]/_components/
Notes:
Only 1 exported function per component file (the main/"exported" component)
If needing to reuse a local component/function/variable/type in another file, it should then be be moved to their own file at that time (and moved to their proper location)
Use
Props
as the name for exported component's interface/typeFor additional local components, append "Props" to the local component name
LocalComponentNameProps
Destructure top-level props within signature (vs first line destructuring)
Then, use first-line destructuring for destructuring individual top-level props when needed
Template
Example
See MUI Styled Components example
MUI styled components
When creating a utility/reusable component with an MUI component as the "base" component:
.
Props
interface should extend the MUI component's native props
Destructure the
sx
prop from...props
(within the component signature/declaration)
Pass in the destructured
sx
prop into the MuiComponent's sx prop after any "default" sx stylingOtherwise, passing the
sx
prop to an instance of the MuiComponent will override any "default"sx
prop styling that exists
Template
Example
Last updated