File tree Expand file tree Collapse file tree 2 files changed +67
-1
lines changed
Expand file tree Collapse file tree 2 files changed +67
-1
lines changed Original file line number Diff line number Diff line change 1+ # Code Style
2+
3+ ## Extracting props from other library components
4+
5+ ``` tsx
6+ import React , { ComponentProps , FC } from ' react' ;
7+ import Link , { LinkProps } from ' next/link' ; // example component
8+
9+ export const AppLink: FC <
10+ LinkProps & ComponentProps <typeof Link > // if LinkProps are available prefer it, otherwise extract from Link (Link is used as example)
11+ > = function AppLink({ href , children , ... props }) {
12+ return (
13+ <Link href = { href } { ... props } >
14+ { children }
15+ </Link >
16+ );
17+ };
18+ ```
19+
20+ ## Component Pattern
21+
22+ Prefer using memoized components:
23+
24+ ``` tsx
25+ import { memo } from ' react' ;
26+
27+ export type CmpProps = {
28+ foo: string ;
29+ };
30+
31+ export const Cmp = memo <CmpProps >(function Cmp({ foo , ... props }) {
32+ // code here
33+ });
34+ ```
35+
36+ If memo is not applicable:
37+
38+ ``` tsx
39+ export type CmpProps = {
40+ foo: string ;
41+ };
42+
43+ export const Cmp: FC <CmpProps > = function Cmp({ foo , ... props }) {
44+ // code here
45+ };
46+ ```
47+
48+ ## Material UI Classes In Selectors
49+
50+ Always use following notation:
51+
52+ ``` tsx
53+ import Input , { inputClasses } from ' @mui/material/Input' ;
54+
55+ const cmp = <Box
56+ sx = { {
57+ [` & .${inputClasses .root } ` ]: {
58+ // styles
59+ },
60+ }}
61+ >
62+ <Input />
63+ </Box >
64+ );
65+ };
66+
67+ ```
Original file line number Diff line number Diff line change 77 "declarationMap" : true ,
88 "declarationDir" : " dist" ,
99 "incremental" : false ,
10- "allowJs" : true ,
1110 /* Build-specific options */
1211 "module" : " esnext" ,
1312 "moduleResolution" : " bundler" ,
You can’t perform that action at this time.
0 commit comments