Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useRive returned component renders nothing #321

Open
t0rbik opened this issue Dec 23, 2024 · 2 comments
Open

useRive returned component renders nothing #321

t0rbik opened this issue Dec 23, 2024 · 2 comments

Comments

@t0rbik
Copy link

t0rbik commented Dec 23, 2024

When we use the basic React example by using default package component export, it renders successfully.
However, changing logic to use useRive causes component, returned from useRive to render empty <canvas>.

Platform: MacOS 15.1, M2, Arc 1.74.0

Reproduction: https://codesandbox.io/p/sandbox/r5wj5x.

Found similar issue #36, but it was closed and there was no reproduction.

@t0rbik t0rbik changed the title useRive returns nothing useRive returned component renders nothing Dec 23, 2024
@gabrieloureiro
Copy link

gabrieloureiro commented Jan 8, 2025

I'm having this same problem but using Next 15 and React 19. The canvas still empty after follow all forums steps

// rive.tsx

"use client";

import { Ref, useEffect } from "react";
import { useRive, useStateMachineInput } from "@rive-app/react-canvas-lite";


type RiveProps = {
  ref?: Ref<HTMLCanvasElement> | undefined;
};

function Rive({ ref }: RiveProps) {
  const { rive, RiveComponent } = useRive({
    src: "/avatar.riv",
    stateMachines: "State Machine 1",
    onLoadError: () => console.log("ERROR LOADING RIVE"),
    onLoad: () => console.log("LOADED RIVE"),
    onStateChange: (state) => console.log("STATE CHANGE", state),
    autoplay: true,
  });

  useEffect(() => {
    if (rive) {
      console.log("Rive object:", rive);
    } else {
      console.log("Rive object not initialized");
    }
  }, [rive]);

  const toggleInput = useStateMachineInput(rive, "State Machine 1", "Toggle");

  useEffect(() => {
    if (toggleInput) {
      console.log("Toggle input is ready:", toggleInput);
    } else {
      console.log("Toggle input not found");
    }
  }, [toggleInput]);

  return (
    <div id="rive-container" className="m-0 h-20 w-20 border-green-500 p-0">
      <RiveComponent
        ref={ref}
        id="rive-component"
        onMouseEnter={() => rive && rive.play()}
        onMouseLeave={() => rive && rive.pause()}
        onClick={() => toggleInput && toggleInput.fire()}
      />
    </div>
  );
}

export { Rive };
// package.json dependencies
"dependencies": {
    "@nextui-org/react": "^2.6.11",
    "@react-three/drei": "^9.120.5",
    "@react-three/fiber": "^8.17.10",
    "@rive-app/react-canvas-lite": "^4.17.5",
    "canvas-confetti": "^1.9.3",
    "motion": "^11.15.0",
    "next": "15.1.3",
    "next-themes": "^0.4.4",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "react-icons": "^5.4.0",
    "tailwind-merge": "^2.6.0",
    "tailwindcss-animate": "^1.0.7",
    "three": "^0.172.0"
  }

Folder public:
Screenshot 2025-01-08 at 07 38 26
HTML:
Screenshot 2025-01-08 at 07 39 42
Current Rive Wrapper:
Screenshot 2025-01-08 at 08 08 25
console.log output:
Screenshot 2025-01-08 at 07 44 23

@gabrieloureiro
Copy link

I've tried with React 18 also. Still rendering nothing

  "dependencies": {
    "@nextui-org/react": "^2.6.11",
    "@react-three/drei": "^9.120.5",
    "@react-three/fiber": "^8.17.10",
    "@rive-app/react-canvas-lite": "^4.17.5",
    "canvas-confetti": "^1.9.3",
    "motion": "^11.15.0",
    "next": "15.1.3",
    "next-themes": "^0.4.4",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-icons": "^5.4.0",
    "tailwind-merge": "^2.6.0",
    "tailwindcss-animate": "^1.0.7",
    "three": "^0.172.0"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3.2.0",
    "@next/eslint-plugin-next": "^15.1.3",
    "@types/node": "^20",
    "@types/react": "^18.0.0",
    "@types/react-dom": "^18.0.0",
    "@typescript-eslint/eslint-plugin": "^8.19.0",
    "@typescript-eslint/parser": "^8.19.0",
    "clsx": "^2.1.1",
    "eslint": "^9.17.0",
    "eslint-config-next": "^15.1.3",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-import": "^2.31.0",
    "eslint-plugin-jsx-a11y": "^6.10.2",
    "eslint-plugin-prettier": "^5.2.1",
    "eslint-plugin-promise": "^7.2.1",
    "eslint-plugin-react": "^7.37.3",
    "eslint-plugin-react-hooks": "^5.1.0",
    "eslint-plugin-simple-import-sort": "^12.1.1",
    "postcss": "^8",
    "prettier": "^3.4.2",
    "prettier-plugin-tailwindcss": "^0.6.9",
    "tailwindcss": "^3.4.1",
    "typescript": "^5"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants