react-babylonjs icon indicating copy to clipboard operation
react-babylonjs copied to clipboard

[BUG] Non-Declarative Method with Typescript

Open Alecell opened this issue 3 years ago • 4 comments

The non-declarative method with typescript has a type error that says that we need to declare a children inside the Scene.

The point is that, when we use the non-declarative way we would not use children inside the Scene so the component should not throw type error when don't have children.

image

"react": "17.0.2", "react-dom": "17.0.2", "react-babylonjs": "^3.0.22", "@babylonjs/core": "^4.2.0", "@babylonjs/gui": "^4.2.0", "typescript": "4.3.4",

Alecell avatar Aug 24 '21 03:08 Alecell

Do you mean that you have ‘<Scene ... />’? I agree that should be allowed, but also if you just want a canvas and Engine and Scene attached without declarative have a look at ‘babylonjs-hook’ NPM. Can you share how you declare your scene?

brianzinn avatar Aug 24 '21 03:08 brianzinn

Yes, the error shows when I use a <Scene />. Thats the snippet:

function NonDeclarative() {
  return (
    <Engine
      adaptToDeviceRatio
      antialias
      canvasId="babylonJS"
      canvasStyle={{ width: '100%' }}
    >
      <Scene onSceneMount={onSceneMount} />
    </Engine>
  );
}

export const App = () => (
  <div style={{ flex: 1, display: 'flex' }}>
    <NonDeclarative />
  </div>
);

The error shows even when I download the non-declarative example.

Alecell avatar Aug 24 '21 14:08 Alecell

I’ll fix that. Thank-you for reporting.

brianzinn avatar Aug 24 '21 17:08 brianzinn

Btw thank your for the recommendation of the babylonjs-hook I was reading about this and makes a lot more sense to use it as I go to the non-declarative approach.

Thanks again 😄

Alecell avatar Aug 24 '21 18:08 Alecell