Component Structure
Overview
General
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
Propsas 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:
.
Propsinterface should extend the MUI component's native props
Destructure the
sxprop from...props(within the component signature/declaration)
Pass in the destructured
sxprop into the MuiComponent's sx prop after any "default" sx stylingOtherwise, passing the
sxprop to an instance of the MuiComponent will override any "default"sxprop styling that exists
Template
Example
Last updated