Skip to content

Maximum update depth exceeded when trying to use React hooks #18

@P-Sanjana

Description

@P-Sanjana

🐛 Problem Description

I'm using unicornstudio-react (^1.4.33) in my Next.js (15.5.4) application. When I try to use useState hook to keep track of scene load, I get React's maximum update depth exceeded error.

📋 Evidence

UnicornSceneComponent.tsx:

'use client';
import { useState } from 'react';
import UnicornScene from 'unicornstudio-react/next';

export default function UnicornSceneComponent() {

const [sceneLoaded, setSceneLoaded] = useState(false);

  return (
    <div style={{ height: '90vh' }}>
      <UnicornScene
        projectId={process.env.UNICORN_STUDIO_PROJECT_ID}
        placeholderClassName='bg-gradient-to-r from-blue-500 to-purple-600 animate-pulse'
        placeholder={<div className="flex items-center justify-center h-full bg-gradient-to-r from-blue-500 to-purple-600 animate-pulse">
          <div className="text-center">
            <div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900 mx-auto"></div>
            <p className="mt-4 text-gray-200">Loading 3D Scene...</p>
          </div>
        </div>}
        onLoad={() => setSceneLoaded(true)}
      />
      
    </div>
  );
}

Error:

Image

🎯 Expected Behavior

  • The UnicornSceneComponent has to render without any issues.
  • After loading the scene, the state variable sceneLoaded should set to true.

📈 Impact Assessment

  • Severity: 🔴 High - Leads to infinite render loops

P.S: It works completely fine without useState.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions