|
1 |
| -import { SearchButton } from "chainlink-algolia-search" |
| 1 | +// src/components/Header/aiSearch/SearchReact.tsx |
| 2 | +import React, { useEffect, useState, ComponentType } from "react" |
| 3 | +import { SearchButtonProps } from "chainlink-algolia-search" |
2 | 4 | import "chainlink-algolia-search/dist/index.css"
|
3 | 5 |
|
4 |
| -export const Search = ({ |
5 |
| - algoliaVars: { algoliaAppId, algoliaPublicApiKey }, |
6 |
| -}: { |
7 |
| - algoliaVars: { algoliaAppId: string; algoliaPublicApiKey: string } |
8 |
| -}) => { |
| 6 | +function AlgoliaSearch({ algoliaVars, categoryOrder, popularCards }) { |
| 7 | + // Only render the component on the client side |
| 8 | + const [isClient, setIsClient] = useState(false) |
| 9 | + const [SearchButtonComponent, setSearchButtonComponent] = useState<ComponentType<SearchButtonProps> | null>(null) |
| 10 | + |
| 11 | + useEffect(() => { |
| 12 | + setIsClient(true) |
| 13 | + import("chainlink-algolia-search").then((module) => { |
| 14 | + setSearchButtonComponent(() => module.SearchButton) |
| 15 | + }) |
| 16 | + }, []) |
| 17 | + |
| 18 | + // Return null during server-side rendering |
| 19 | + if (!isClient || !SearchButtonComponent) { |
| 20 | + return <div></div> |
| 21 | + } |
| 22 | + |
9 | 23 | return (
|
10 |
| - <SearchButton |
11 |
| - algoliaAppId={algoliaAppId} |
12 |
| - algoliaPublicApiKey={algoliaPublicApiKey} |
13 |
| - popularCards={[ |
14 |
| - { |
15 |
| - url: "https://dev.chain.link/resources/quickstarts", |
16 |
| - imgSrc: "/images/algolia/quick-start.png", |
17 |
| - label: "Quickstarts", |
18 |
| - }, |
19 |
| - { url: "https://dev.chain.link/tools", imgSrc: "/images/algolia/tools.png", label: "Tools" }, |
20 |
| - ]} |
| 24 | + <SearchButtonComponent |
| 25 | + algoliaAppId={algoliaVars.algoliaAppId} |
| 26 | + algoliaPublicApiKey={algoliaVars.algoliaPublicApiKey} |
| 27 | + categoryOrder={categoryOrder} |
| 28 | + popularCards={popularCards} |
21 | 29 | />
|
22 | 30 | )
|
23 | 31 | }
|
| 32 | + |
| 33 | +export default AlgoliaSearch |
0 commit comments