Access React Object from inside a JS page?

I have a ReactVr object that I am processing using the code below. After initializing React, I periodically receive server updates that I want to pass to React as a props, how can I do this? Can props in a React object be set from my "regular" JS?

ReactVR.init(
    './build/index.bundle.js',
    document.body,
    // third argument is a map of initialization options
    {
      initialProps: {
        source: 'world.json',
         userType: "typ1"
        },
      cursorVisibility: 'visible'
    }
  );

Edit: Server updates occur through a connection with Websockets, but messages are not accepted from within React, only in "normal" JS.

In "normal" JS, this returns data from the server, if I use the same thing inside React, the connection opens, but the message is never received. However, messages can be sent from React.

socket.addEventListener('message', function (event) {

        console.log('Message from server ', event.data);

  });
+4
source share
1 answer

.

: https://facebook.imtqy.com/react-vr/docs/native-modules.html

client.js, vr .

init client.js

const socketsModule = new SocketsModule();

, , :

export class SocketsModule extends Module {
  constructor() {
    super('SocketsModule');
  }

  init() {
  }

  customMethod() {
    // Do fun stuff here
  }

}

VR , :

const SocketsModule= NativeModules.SocketsModule;

:

SocketsModule.customMethod();
0

Source: https://habr.com/ru/post/1690268/


All Articles