# Reactylon: The React Framework for XR

**URL:** <https://forum.babylonjs.com/t/reactylon-the-react-framework-for-xr/55382>\
**Category:** Demos and projects\
**Tags:** react, typescript, react-native\
**Created:** [December 15, 2024, 4:57pm UTC](https://forum.babylonjs.com/t/reactylon-the-react-framework-for-xr/55382 "2024-12-15T16:57:47Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![SimoneDev](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/simonedev/32/44252_2.png) [@SimoneDev](https://forum.babylonjs.com/u/SimoneDev)\
**Post date:** [January 29, 2025, 4:43pm UTC](https://forum.babylonjs.com/t/reactylon-the-react-framework-for-xr/55382/21 "2025-01-29T16:43:33Z")

</div>

> Perhaps you’ve already exposed this sort of interface/api, but is there a way to create many instances of the same mesh (they share the same geometry, and optionally share the same materials)

Yes, there is a dedicated section about cloning/instancing: [Copies, Clones and Instances | Reactylon](https://www.reactylon.com/docs/meshes/copies-clones-and-instances#instance), the sugar syntax is the `instanceFrom` prop.

> Going off the example you provided, lets say your group of boxes constitutes a single mesh tree. I want to create many instances that all respond to the same hide/show logic at an individual level. That is each group of boxes can be toggled on/off, and each group of boxes can hide/show individual boxes.

Great example to showcase. As the goal is to share the same materials across the boxes, we will use instances instead of clones and, for simplicity, instead of showing or hiding a single box, we will scale its dimensions.

> **[Reactylon - Multiple instances - StackBlitz](https://stackblitz.com/edit/reactylon-multiple-instances?file=src%2FContent.tsx,src%2FBoxGroup.tsx)**
>
> A React project based on react, react-dom, @babylonjs/core, @babylonjs/gui, @babylonjs/havok, reactylon, @babel/core, @babel/preset-env, @babel/preset-typescript, @babel/register, @types/node, @types/react, @types/react-dom, @types/webpack,...

There are two `BoxGroup` components (representing your single mesh tree), each accepting the following props:

- `name`: the name of the box group
- `count`: the number of the boxes
- `color`: the color of the boxes
- `positionY`: the Y position of the box group

When you click on a box, its size toggles between 1 and 2. This change is handled acting on the ref the box so it won’t trigger a re-render.

At the top level, the visibility of the two `BoxGroup` is managed through HTML buttons, controlled by an external context (primary renderer) and React state. When a `BoxGroup` is shown, it creates new instances, while it is hidden, it disposes all of them.  
Note: the visibility of a `BoxGroup` doesn’t influence the state of the other one (for instance, try to click on some boxes of one `BoxGroup` and then toggle the visibility of the other one).

The example is pretty simple, but it demonstrates several key-concepts:

1. How to sync external updates with the Reactylon rendering context (from primary to secondary renderer)
2. How to change a property without trigger a re-render (by using ref)
3. How a React component-based approach simplifies managing a unified entity by encapsulating count, color, and events, making updates and interactions more efficient and scalable.

---

_[View the full topic](https://forum.babylonjs.com/t/reactylon-the-react-framework-for-xr/55382)._
