Skip to content

Commit 70191fb

Browse files
committed
refactor(Render): simplify RenderComponent by removing mesh instance registration
- Removed the mesh instance registration logic and context provider from RenderComponent. - Updated the component to directly use the props for rendering without additional state management. - Retained the container rendering logic for asset types.
1 parent a9596f4 commit 70191fb

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed

packages/lib/src/components/Render.tsx

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
11
"use client"
22

3-
import { FC, ReactElement, useRef, createContext, useContext, useCallback } from "react";
3+
import { FC, ReactElement, createContext, useContext } from "react";
44
import { useComponent } from "../hooks/index.ts";
55
import { MeshInstance } from "./MeshInstance.tsx";
66
import { Asset, Entity, MeshInstance as PcMeshInstance, type RenderComponent as PcRenderComponent } from "playcanvas";
77
import { PublicProps, Serializable } from "../utils/types-utils.ts";
88
import { getStaticNullApplication, validatePropsPartial, Schema } from "../utils/validation.ts";
99
import { createComponentDefinition } from "../utils/validation.ts";
10-
import { useParent } from "../hooks/use-parent.tsx";
10+
import { Container } from "../Container.tsx";
1111

1212
const MeshInstanceContext = createContext<((instance: PcMeshInstance) => void) | null>(null);
1313

1414
export const useMeshInstanceRegistration = () => useContext(MeshInstanceContext);
1515

1616
const RenderComponent: FC<RenderProps> = (props) => {
17-
const { children, ...rest } = props;
18-
19-
const parent : Entity = useParent();
20-
const meshInstancesRef = useRef<PcMeshInstance[]>([]);
21-
22-
useComponent("render", rest, componentDefinition.schema as Schema<RenderProps, PcRenderComponent>);
23-
24-
const registerMeshInstance = useCallback((instance: PcMeshInstance) => {
25-
if (!meshInstancesRef.current.includes(instance)) {
26-
meshInstancesRef.current.push(instance);
27-
if (parent.render) {
28-
(parent.render as PcRenderComponent).meshInstances = meshInstancesRef.current;
29-
}
30-
}
31-
}, [parent]);
32-
33-
return (
34-
<MeshInstanceContext.Provider value={registerMeshInstance}>
35-
{children}
36-
</MeshInstanceContext.Provider>
37-
);
17+
useComponent("render", props, componentDefinition.schema as Schema<RenderProps, PcRenderComponent>);
18+
return null;
3819
}
3920

4021
/**
@@ -63,11 +44,11 @@ export const Render: FC<RenderProps> = (props) => {
6344
if(safeProps.type === "asset" && !safeProps.asset) return null;
6445

6546
// Render a container if the asset is a container
66-
// if (safeProps.asset?.type === 'container') {
67-
// return <Container asset={safeProps.asset as Asset} >
68-
// { safeProps.children }
69-
// </Container>
70-
// }
47+
if (safeProps.asset?.type === 'container') {
48+
return <Container asset={safeProps.asset as Asset} >
49+
{ safeProps.children }
50+
</Container>
51+
}
7152

7253
// console.log('safeProps', safeProps);
7354

0 commit comments

Comments
 (0)