{"id":13760589,"url":"https://github.com/splinetool/react-spline","last_synced_at":"2025-05-16T02:08:55.741Z","repository":{"id":37287339,"uuid":"429731156","full_name":"splinetool/react-spline","owner":"splinetool","description":"React component for Spline scenes.","archived":false,"fork":false,"pushed_at":"2024-06-20T13:57:39.000Z","size":3948,"stargazers_count":1269,"open_issues_count":35,"forks_count":66,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-04-08T12:12:19.083Z","etag":null,"topics":["react"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/splinetool.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-11-19T08:58:16.000Z","updated_at":"2025-04-08T07:57:14.000Z","dependencies_parsed_at":"2022-07-12T11:34:40.222Z","dependency_job_id":"f8303aaf-9467-4ae8-b2c8-ee693bfaaa1a","html_url":"https://github.com/splinetool/react-spline","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splinetool%2Freact-spline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splinetool%2Freact-spline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splinetool%2Freact-spline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/splinetool%2Freact-spline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/splinetool","download_url":"https://codeload.github.com/splinetool/react-spline/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254453655,"owners_count":22073617,"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","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":["react"],"created_at":"2024-08-03T13:01:13.605Z","updated_at":"2025-05-16T02:08:55.697Z","avatar_url":"https://github.com/splinetool.png","language":"TypeScript","readme":"[![](https://raw.githubusercontent.com/splinetool/react-spline/main/.github/screenshots/hero.png)](https://my.spline.design/splinereactlogocopycopy-eaa074bf6b2cc82d870c96e262a625ae/)\n\n# react-spline\n\n**react-spline** allows you to export and use Spline scenes directly in your React websites.\n\n🌈 [Spline](https://spline.design/) is a friendly 3d collaborative design tool for the web.\n\n[Website](https://spline.design/) \u0026mdash;\n[Twitter](https://twitter.com/splinetool) \u0026mdash;\n[Community](https://discord.gg/M9hNDMqvnw) \u0026mdash;\n[Documentation](https://docs.spline.design/)\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Next.js](#nextjs)\n  - [Read and modify Spline objects](#read-and-modify-spline-objects)\n  - [Listen to events](#listen-to-events)\n  - [Trigger Spline events from outside](#trigger-spline-events-from-outside)\n  - [Lazy loading](#lazy-loading)\n- [API](#api)\n  - [Spline Component Props](#spline-component-props)\n  - [Spline App Methods](#spline-app-methods)\n  - [Spline Events](#spline-events)\n- [Contributing](#contributing)\n\n## Install\n\n```bash\nyarn add @splinetool/react-spline @splinetool/runtime\n```\n\nor\n\n```bash\nnpm install @splinetool/react-spline @splinetool/runtime\n```\n\n## Usage\n\nTo use react-spline, first you have to go to the Spline editor, click on the **Export** button, select \"**Code**\" and then \"**React**\".\n\nYou should see this:\n\n\u003cimg width=\"250\" src=\"https://raw.githubusercontent.com/splinetool/react-spline/main/.github/screenshots/react-export-pane.png\"\u003e\n\nYou can copy the URL and pass it to the `\u003cSpline /\u003e` component in react:\n\n```jsx\nimport Spline from '@splinetool/react-spline';\n\nexport default function App() {\n  return (\n    \u003cdiv\u003e\n      \u003cSpline scene=\"https://prod.spline.design/6Wq1Q7YGyM-iab9i/scene.splinecode\" /\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\nYou should be able to see the scene you exported in your React app.\n\n[![](https://raw.githubusercontent.com/splinetool/react-spline/main/.github/screenshots/example-basic.png)](https://codesandbox.io/s/sweet-rain-28pcxt?file=/src/App.js)\n\n**NOTE**: If you are experiencing CORS issues, you can download the .splinecode file and self-host it; this will fix any CORS issue. To download, go to Spline's code export panel and click on the download icon visible in the prod.spline textarea.\n\n### Next.js\n\nYou can use this library in Next.js as well to take advantage of Server Side Rendering. By default the library will render on the client only, but if you use the import `@splinetool/react/next` the server will render an autogenerated blurred placeholder.\n\nHere is an example. Export as `Next.js` from the Spline editor to autogenerate the placeholder.\n\n```js\nimport Spline from '@splinetool/react-spline/next';\n\nexport default function App() {\n  return (\n    \u003cdiv\u003e\n      \u003cSpline scene=\"https://prod.spline.design/KFonZGtsoUXP-qx7/scene.splinecode\" /\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n### Read and modify Spline objects\n\nYou can query any Spline object via `findObjectByName` or `findObjectById`.\n\n_(You can get the ID of the object by right-clicking on it and selecting `Copy Development Object ID`)._\n\n```jsx\nimport { useRef } from 'react';\nimport Spline from '@splinetool/react-spline';\n\nexport default function App() {\n  const cube = useRef();\n\n  function onLoad(spline) {\n    const obj = spline.findObjectByName('Cube');\n    // or\n    // const obj = spline.findObjectById('8E8C2DDD-18B6-4C54-861D-7ED2519DE20E');\n\n    // save it in a ref for later use\n    cube.current = obj;\n  }\n\n  function moveObj() {\n    console.log(cube.current); // Spline Object =\u003e { name: 'Cube', id: '8E8C2DDD-18B6-4C54-861D-7ED2519DE20E', position: {}, ... }\n\n    // move the object in 3D space\n    cube.current.position.x += 10;\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cSpline\n        scene=\"https://prod.spline.design/6Wq1Q7YGyM-iab9i/scene.splinecode\"\n        onLoad={onLoad}\n      /\u003e\n      \u003cbutton type=\"button\" onClick={moveObj}\u003e\n        Move Cube\n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n### Listen to Spline Events\n\nYou can listen to any Spline Event you set in the Events panel of the editor by attaching a listener to the Spline component.\n\n```jsx\nimport Spline from '@splinetool/react-spline';\n\nexport default function App() {\n  function onSplineMouseDown(e) {\n    if (e.target.name === 'Cube') {\n      console.log('I have been clicked!');\n    }\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cSpline\n        scene=\"https://prod.spline.design/6Wq1Q7YGyM-iab9i/scene.splinecode\"\n        onSplineMouseDown={onSplineMouseDown}\n      /\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\nYou can find a list of all of the Spline Event listeners in the [Spline Component Props](#spline-component-props) section.\n\n### Trigger Spline events from outside\n\nYou can trigger any animation Event you set in the Events panel in the Spline Editor.\n\nYou can use the `emitEvent` function via the spline ref, passing the [event type](#spline-events) and the ID of your object.\n\n_(You can get the ID of the object in the `Develop` pane of the right sidebar)._\n\n```jsx\nimport { useRef } from 'react';\nimport Spline from '@splinetool/react-spline';\n\nexport default function App() {\n  const spline = useRef();\n\n  function onLoad(splineApp) {\n    // save the app in a ref for later use\n    spline.current = splineApp;\n  }\n\n  function triggerAnimation() {\n    spline.current.emitEvent('mouseHover', 'Cube');\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cSpline\n        scene=\"https://prod.spline.design/6Wq1Q7YGyM-iab9i/scene.splinecode\"\n        onLoad={onLoad}\n      /\u003e\n      \u003cbutton type=\"button\" onClick={triggerAnimation}\u003e\n        Trigger Spline Animation\n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\nOr you can query the spline object first, and then trigger the event:\n\n```jsx\nimport { useRef } from 'react';\nimport Spline from '@splinetool/react-spline';\n\nexport default function App() {\n  const objectToAnimate = useRef();\n\n  function onLoad(spline) {\n    const obj = spline.findObjectByName('Cube');\n    // save the object in a ref for later use\n    objectToAnimate.current = obj;\n  }\n\n  function triggerAnimation() {\n    objectToAnimate.current.emitEvent('mouseHover');\n  }\n\n  return (\n    \u003cdiv\u003e\n      \u003cSpline\n        scene=\"https://prod.spline.design/6Wq1Q7YGyM-iab9i/scene.splinecode\"\n        onLoad={onLoad}\n      /\u003e\n      \u003cbutton type=\"button\" onClick={triggerAnimation}\u003e\n        Trigger Spline Animation\n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\nYou can find a list of all of the Spline Events you can pass to the `emitEvent` function in the [Spline Events](#spline-events) section.\n\n### Lazy loading\n\nTo start loading react-spline after the whole website has finished loading, we can use lazy-loading. This technique can be achieved using [`React.lazy()`](https://it.reactjs.org/docs/code-splitting.html#reactlazy) in combination with dynamic imports:\n\n```jsx\nimport React, { Suspense } from 'react';\n\nconst Spline = React.lazy(() =\u003e import('@splinetool/react-spline'));\n\nexport default function App() {\n  return (\n    \u003cdiv\u003e\n      \u003cSuspense fallback={\u003cdiv\u003eLoading...\u003c/div\u003e}\u003e\n        \u003cSpline scene=\"https://prod.spline.design/6Wq1Q7YGyM-iab9i/scene.splinecode\" /\u003e\n      \u003c/Suspense\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\nMore info in the [relative React documentation](https://it.reactjs.org/docs/code-splitting.html).\n\n## API\n\n### Spline Component Props\n\nThese are all the props you can pass to the `\u003cSpline /\u003e` component.\n\n| Name                  | Type                            | Description                                                                                                                   |\n| --------------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |\n| `scene`               | `string`                        | Scene file                                                                                                                    |\n| `onLoad?`             | `(spline: Application) =\u003e void` | Gets called once the scene has loaded. The `spline` parameter is an instance of the [Spline Application](#spline-app-methods) |\n| `renderOnDemand?`     | `boolean`                       | Wether or not to enable [on demand rendering](https://threejs.org/manual/#en/rendering-on-demand). Default `true`.            |\n| `className?`          | `string`                        | CSS classes                                                                                                                   |\n| `style?`              | `object`                        | CSS style                                                                                                                     |\n| `id?`                 | `string`                        | Canvas id                                                                                                                     |\n| `ref?`                | `React.Ref\u003cHTMLDivElement\u003e`     | A ref pointing to div container element.                                                                                      |\n| `onSplineMouseDown?`  | `(e: SplineEvent) =\u003e void`      | Gets called once a Spline `Mouse Down` event is fired                                                                         |\n| `onSplineMouseHover?` | `(e: SplineEvent) =\u003e void`      | Gets called once a Spline `Mouse Hover` event is fired                                                                        |\n| `onSplineMouseUp?`    | `(e: SplineEvent) =\u003e void`      | Gets called once a Spline `Mouse Up` event is fired                                                                           |\n| `onSplineKeyDown?`    | `(e: SplineEvent) =\u003e void`      | Gets called once a Spline `Key Down` event is fired                                                                           |\n| `onSplineKeyUp?`      | `(e: SplineEvent) =\u003e void`      | Gets called once a Spline `Key Up` event is fired                                                                             |\n| `onSplineStart?`      | `(e: SplineEvent) =\u003e void`      | Gets called once a Spline `Start` event is fired                                                                              |\n| `onSplineLookAt?`     | `(e: SplineEvent) =\u003e void`      | Gets called once a Spline `Look At` event is fired                                                                            |\n| `onSplineFollow?`     | `(e: SplineEvent) =\u003e void`      | Gets called once a Spline `Mouse Up` event is fired                                                                           |\n| `onSplineScroll?`     | `(e: SplineEvent) =\u003e void`      | Gets called once a Spline `Scroll` event is fired                                                                             |\n\n### Spline App Methods\n\nThe object exposed as a first argument of the `onLoad` function, is a Spline Application. You can call all these different methods on it.\n\n| Name               | Type                                                       | Description                                                                                                                 |\n| ------------------ | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |\n| `emitEvent`        | `(eventName: SplineEventName, nameOrUuid: string) =\u003e void` | Triggers a Spline event associated to an object with provided name or uuid.                                                 |\n| `emitEventReverse` | `(eventName: SplineEventName, nameOrUuid: string) =\u003e void` | Triggers a Spline event associated to an object with provided uuid in reverse order. Starts from last state to first state. |\n| `findObjectById`   | `(uuid: string) =\u003e SPEObject`                              | Searches through scene's children and returns the object with that uuid.                                                    |\n| `findObjectByName` | `(name: string) =\u003e SPEObject`                              | Searches through scene's children and returns the first object with that name.                                              |\n| `setZoom`          | `(zoom: number) =\u003e void`                                   | Sets the initial zoom of the scene.                                                                                         |\n\n### Spline Events\n\nThese are all the Spline event types that you can pass to the `emitEvent` or `emitEventReverse` function.\n\n| Name         | Description                                   |\n| ------------ | --------------------------------------------- |\n| `mouseDown`  | Refers to the Spline `Mouse Down` event type  |\n| `mouseHover` | Refers to the Spline `Mouse Hover` event type |\n| `mouseUp`    | Refers to the Spline `Mouse Up` event type    |\n| `keyDown`    | Refers to the Spline `Key Down` event type    |\n| `keyUp`      | Refers to the Spline `Key Up` event type      |\n| `start`      | Refers to the Spline `Start` event type       |\n| `lookAt`     | Refers to the Spline `Look At` event type     |\n| `follow`     | Refers to the Spline `Mouse Up` event type    |\n\n## Contributing\n\nWe use [yarn](https://yarnpkg.com/), install the dependencies like this:\n\n```bash\nyarn\n```\n\n### Development\n\nServe the `example` folder at localhost:3000\n\n```bash\nyarn dev\n```\n\n### Build Library\n\n```bash\nyarn build\n```\n\n### Publish on npm\n\n```bash\nyarn publish\n```\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsplinetool%2Freact-spline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsplinetool%2Freact-spline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsplinetool%2Freact-spline/lists"}