Skip to content

Commit 49b34b5

Browse files
committed
docs: add inline documentation for CustomPrefixProvider
1 parent 9a7e1be commit 49b34b5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/components/rsc/CustomPrefixProvider.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,46 @@ interface CustomPrefixProviderProps {
66
customPrefix: string
77
}
88

9+
/**
10+
* React component that provides a custom CSS prefix for Font Awesome icons.
11+
*
12+
* Use this if your React application uses server-side rendering (e.g. NextJS, Vite/Remix, Astro, etc.)
13+
* to ensure the `cssPrefix` is set correctly in the client-side prior to hydration.
14+
*
15+
* To ensure this works correctly, be sure to render this provider at the top level of your application.
16+
* It has been built with `"use client"` but not as a typical provider that would wrap the application.
17+
* This means you don't have to worry about turning your whole application into a client component when using this provider
18+
* at the top level.
19+
*
20+
* @example
21+
* ```tsx
22+
* // In Next.js App Router - `app/layout.tsx`
23+
* import '@fortawesome/fontawesome-svg-core/styles.css'
24+
* import { config } from '@fortawesome/fontawesome-svg-core'
25+
* import { CustomPrefixProvider } from '@fortawesome/react-fontawesome/components/rsc/CustomPrefixProvider'
26+
*
27+
* const CUSTOM_FA_CSS_PREFIX = 'my-custom-prefix'
28+
*
29+
* config.autoAddCss = false
30+
* config.cssPrefix = CUSTOM_FA_CSS_PREFIX
31+
*
32+
* export default function RootLayout({ children }) {
33+
* return (
34+
* <html>
35+
* {
36+
* // Render the component in isolation before the opening <body> tag
37+
* }
38+
* <CustomPrefixProvider customPrefix={CUSTOM_FA_CSS_PREFIX} />
39+
* <body>
40+
* {children}
41+
* </body>
42+
* </html>
43+
* )
44+
* }
45+
* ```
46+
*
47+
* @returns null - This is a "void" component used purely for side effects.
48+
*/
949
export const CustomPrefixProvider = ({
1050
customPrefix,
1151
}: CustomPrefixProviderProps): null => {

0 commit comments

Comments
 (0)