{"id":22480147,"url":"https://github.com/findify/react-ssr","last_synced_at":"2025-08-29T17:40:31.585Z","repository":{"id":53995771,"uuid":"346306704","full_name":"findify/react-ssr","owner":"findify","description":"Next.js + Findify example","archived":false,"fork":false,"pushed_at":"2021-03-22T12:32:28.000Z","size":181,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-08-14T07:44:23.551Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/findify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-10T09:49:30.000Z","updated_at":"2021-03-22T12:32:30.000Z","dependencies_parsed_at":"2022-08-13T05:50:41.688Z","dependency_job_id":null,"html_url":"https://github.com/findify/react-ssr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/findify/react-ssr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findify%2Freact-ssr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findify%2Freact-ssr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findify%2Freact-ssr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findify%2Freact-ssr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/findify","download_url":"https://codeload.github.com/findify/react-ssr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findify%2Freact-ssr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272733360,"owners_count":24984261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-29T02:00:10.610Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T15:19:53.198Z","updated_at":"2025-08-29T17:40:31.546Z","avatar_url":"https://github.com/findify.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e This is a minimal example of how to use Findify` [Agent](https://github.com/findify/findify-js/tree/develop/packages/agent) + [React-connect](https://github.com/findify/findify-js/tree/develop/packages/react-connect) in [Next.js](https://nextjs.org/learn) app.\n\n\nFindify SDK and Agent already include server-side request logic. This repo will explain how to separate Agents on server, make request that include cookies and reuse response on the client side.\n\n## Setup\n```bash\nyarn add @findify/react-connect @findify/change-emitter universal-cookie\nnpm i @findify/react-connect @findify/change-emitter universal-cookie\n```\n\n## Create Feature\nFeature is an instance of Search, Autocomplete, Recommendation or Smart Collection.\nAn axample of feature creator can be found in `./components/Findify.js`. \nFeel free to modify the code, but keep in mind - you need to provide the **same user props** on the backend and the client.\n\n```javascript\n\n// We are preparing closure with Agent and Provider for specific feature\n// Analytics instance will be automatically created inside Provider and provided down via React context\nconst Search = createWidgetCreator('[widget type]', '[API key]');\n\n // Make request on Server and pick user from req.headers.cookies\nexport async function getServerSideProps({ req, query }) {\n  // Optional Request Body\n  const params = { q: query \u0026\u0026 query.q || '' };\n  \n  // Optional persistent request params that will be merged with request params on every request\n  // `slot` for smart-collections and recommendations should be passed here\n  const defaults = { slot: 'collections/some-collections' };\n  \n  const state = await Search.request({\n    req, // Required if you need to pick user from cookies on server\n    params,\n    defaults\n  });\n  \n  return {\n    props: { state, defaults, params },\n  }\n}\n\n```\n\n## Component\n`createWidgetCreator` returns 'Provider' component which contains logic for state rehydration. [READ MORE](https://developers.findify.io/page/findify-react-connect-reference) about Findify` connections and providers\n\n```javascript\nconst Search = createWidgetCreator('[widget type]', '[API key]')\n\nreturn ({ state, defaults }) =\u003e {\n  return (\n    \u003cSearch.Provider cache={state} defaults={defaults}\u003e\n    { \n      // Children here are able to connect to the feature state\n    }\n    \u003c/Search.Provider\u003e\n  )\n}\n```\n\nYou can also add `config` to providers prop. This prop will be available in all connects and hooks.\n\nYou can use either HOC or a Hook version of connector as they return the same props (`connectItems` = `useItems`).\n\n## How To\n\n### Listen to state update\n```js\nimport { useQuery } from '@findify/react-connect'\n\n... \n\n() =\u003e {\n  const { query } = useQuery();\n  useEffect(() =\u003e {\n    console.log('Query has been changed')\n  }, [query])\n  return null\n}\n```\n### Update Agent in some component\n\n```js\nconst Search = createWidgetCreator('[widget type]', '[API key]')\n\n...\n\n() =\u003e {\n  return (\n    \u003cinput onChange={(e) =\u003e Search.getAgent().set('q', e.target.value)}/\u003e\n  )\n}\n```\n\n---\nYou can find more information and cases of connectors and hooks in our [react-components](https://github.com/findify/findify-js/tree/develop/packages/react-components) repository.\n\n\n### Send analytics\n\nEvery connector or hook returns `{ analytics }` instance which could be used to send events to Findify\n\n\u003e Basic example\n```js\nimport { useConfig } from '@findify/react-connect'\n() =\u003e {\n  const { analytics } = useConfig();\n  analytics.sendEvent('view-page', { ... })\n}\n```\n\n### Update cart event\nShould be sent after product has been added to the cart and contain the whole cat content\n```javascript\nimport { useConfig } from '@findify/react-connect'\nconst { analytics } = useConfig();\nanalytics.sendEvent('update-cart', {\n    line_items: [ // Array of products\n      {\n        item_id: \"PRODUCT_ID_1\",\n        quantity: 1,\n        unit_price: 22.35,\n        variant_item_id: \"VARIANT_ID_1\"\n      }\n    ]\n });\n```\n### Purchase event\n\n```javascript\nimport { useConfig } from '@findify/react-connect'\n\nconst { analytics } = useConfig();\n analytics.sendEvent('purchase', {\n    currency: \"EUR\",\n    line_items: [// Array of products\n      {\n        item_id: \"PRODUCT_ID_1\",\n        quantity: 1,\n        unit_price: 288.28,\n        variant_item_id: \"VARIANT_ID_1\"\n      },\n    ],\n    order_id: \"ORDER_ID\",\n    revenue: 288.28\n });\n```\n### View page event\nShould be sent every time user lands on the product page\n```javascript\nconst { analytics } = useConfig();\n analytics.sendEvent('view-page', {\n  item_id: \"PRODUCT_ID\",\n  variant_item_id: \"PRODUCT_VARIANT_ID\"\n })\n```\n### Product click event\nProduct Item contains `sendAnalytics` method by calling which all necessary data will be send to Findify\n```javascript\nimport { useItems } from '@findify/react-connect'\n  const { items } = useItems();\n  return items.map((item) =\u003e\n    \u003ca onClick={() =\u003e item.sendAnalytics()} key={item.hashCode()}\u003e\n      {item.get('title')}\n    \u003c/a\u003e\n  )\n```\nif you want to send analytics outside of Provider, you can create analytics instance manually.\n[Analytics Reference](https://developers.findify.io/page/findify-analytics#setup) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffindify%2Freact-ssr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffindify%2Freact-ssr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffindify%2Freact-ssr/lists"}