# How to get Scene reference on React? Should I program on React being total new using BabylonJS?

**URL:** <https://forum.babylonjs.com/t/how-to-get-scene-reference-on-react-should-i-program-on-react-being-total-new-using-babylonjs/20596>\
**Category:** Questions\
**Created:** [May 5, 2021, 6:07pm UTC](https://forum.babylonjs.com/t/how-to-get-scene-reference-on-react-should-i-program-on-react-being-total-new-using-babylonjs/20596 "2021-05-05T18:07:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khanon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/khanon/32/14980_2.png) [@Khanon](https://forum.babylonjs.com/u/Khanon)\
**Post date:** [May 5, 2021, 6:07pm UTC](https://forum.babylonjs.com/t/how-to-get-scene-reference-on-react-should-i-program-on-react-being-total-new-using-babylonjs/20596/1 "2021-05-05T18:07:23Z")

</div>

Hi.

I have an Engine, Scene and Mesh on App.tsx.  
I can gget the reference of Engine and Mesh, but I can’t get the reference of the Scene.

How could I get the reference of the scene to control it?  
Should I add the Engine Component to the React renderer and then create the scene manually to get control of it?

I’m also seeing that 95% of examples are Typescript code without any React framework.  
I’m thinking seriously to get rid from React and program my site using just Typescript.  
I’m total new with BabylonJS… should I get rid from React?  
My knowledge of React is also limited, I just wanted to learn React and Babylon JS at the same time…

 ![Screenshot_1](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/3/388c5add84c48ce3ea40109b7b830d8406cdbde2.png)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Foxhoundn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/foxhoundn/32/15613_2.png) [@Foxhoundn](https://forum.babylonjs.com/u/Foxhoundn)\
**Post date:** [May 6, 2021, 7:32am UTC](https://forum.babylonjs.com/t/how-to-get-scene-reference-on-react-should-i-program-on-react-being-total-new-using-babylonjs/20596/3 "2021-05-06T07:32:28Z")

</div>

Hi Khanon!

First of all - WELCOME! - it’s great to have you! You chose 2 incredibly amazing technologies for your journey 🙂 With that said, I would (personally) suggest to take it one step at a time - learn 1 then 2.

If you want to learn React I would start with that, but you can obviously use BabylonJS without React, or use React just as the UI / Rendering layer.

Regarding your question - looking at the scene component here: [react-babylonjs/Scene.tsx at master · brianzinn/react-babylonjs · GitHub](https://github.com/brianzinn/react-babylonjs/blob/master/src/Scene.tsx) we can see that it’s just a Context provider that does not render anything except children, and it does not utilise ref forwarding, so the `ref` you pass it, is not passed down on it’s children.

You can see in your code that the `ref` on has red underline, which I bet says that `ref` is not a supported prop on .

To get the Scene, you can just replace the `ref` property with `onSceneMount` like this.

```auto
<SceneComponent onSceneMount={({ scene, canvas } => /* do whatever you need to with scene and canvas */)} ..... />

```

You can see the code that drives this below, it’s on line 136 in the file I have mentioned.

```auto
if (typeof props.onSceneMount === 'function') {
      props.onSceneMount({
        scene: scene,
        canvas: scene.getEngine().getRenderingCanvas()!
      });
}

```

Hope this helps, please let me know if you have any more questions.

---

<div class="post-metadata">

**Author:** ![Khanon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/khanon/32/14980_2.png) [@Khanon](https://forum.babylonjs.com/u/Khanon)\
**Post date:** [May 6, 2021, 5:00pm UTC](https://forum.babylonjs.com/t/how-to-get-scene-reference-on-react-should-i-program-on-react-being-total-new-using-babylonjs/20596/4 "2021-05-06T17:00:22Z")

</div>

Thanks for the reply.

As I’m seeing most of tutorials and code examples are without React framework I agree and I will get rid from it.

Thanks for the explanation about how to get the scene tho 🙂

Best regards.

---

<div class="post-metadata">

**Author:** ![jelster](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jelster/32/25881_2.png) [@jelster](https://forum.babylonjs.com/u/jelster)\
**Post date:** [May 6, 2021, 10:18pm UTC](https://forum.babylonjs.com/t/how-to-get-scene-reference-on-react-should-i-program-on-react-being-total-new-using-babylonjs/20596/5 "2021-05-06T22:18:05Z")

</div>

Welcome to the start of an incredible journey!!

React just comprises the application hosting the Babylon.js framework and WebGXX renderer - @Foxhoundn is wise to suggest taking on one at a time.  
Unless you’re building a web application which involves 3D rendering (like a product catalog) that involves heavy HTML-to-canvas integration, you’ll spend most of your time looking at stuff in only one of these different “worlds”.

There is a TypeScript starter repository that the BJS team informally maintains - see this thread for more [BabylonJS boilerplate for start project with TypeScrpit](https://forum.babylonjs.com/t/babylonjs-boilerplate-for-start-project-with-typescrpit/2177)

---

<div class="post-metadata">

**Author:** ![Khanon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/khanon/32/14980_2.png) [@Khanon](https://forum.babylonjs.com/u/Khanon)\
**Post date:** [May 7, 2021, 6:01pm UTC](https://forum.babylonjs.com/t/how-to-get-scene-reference-on-react-should-i-program-on-react-being-total-new-using-babylonjs/20596/6 "2021-05-07T18:01:30Z")

</div>

Thanks @jelster for the advice.  
Definitely I will remove React yeah 🙂 Then I can focus on BabylonJS.  
I don’t plan being a pro of BabylonJS, but creating a cool personal website to show my projects etc 🙂

---

<div class="post-metadata">

**Author:** ![MarkM](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@MarkM](https://forum.babylonjs.com/u/MarkM)\
**Post date:** [May 8, 2021, 6:26am UTC](https://forum.babylonjs.com/t/how-to-get-scene-reference-on-react-should-i-program-on-react-being-total-new-using-babylonjs/20596/7 "2021-05-08T06:26:28Z")

</div>

@Khanon for my first project I used BJS with javascript but for my second project i used React+BJS (still using javascript). I have found React adds so much more ability but it does have its own learning curve. I use hooks exclusively and no components. Both my projects are still under dev. I would agree with learning one at a time but keep in mind the option to use both together.
