0

我在我的 MacBook 上开发了一个 React-Electron-Boilerplate (with Redux) 应用程序。由于它稍后需要在我的 RaspberryPi 上运行,所以我不时在那里对其进行测试。到现在为止,一切都是一样的……

我通过 WebSocket 检索协调并根据选择的movementSpec. 但不知何故,这在 macOS 上运行时的工作方式与在 Rasbian 上运行时不同。

const Websocket = () => {
  // Dispatch for updating the hardware output position
  const positionDispatch = useDispatch<Dispatch<PositionActions>>();

  // Getting movementSpec to adjust coordinates accordingly
  const { movementSpec } = useSelector(
    (state: AppState) => state.movementSpecs
  );

  const ws = new WebSocket(webSocketBaseAddress);

  // Retrieve data from websocket
  ws.onmessage = useCallback(
    (event) => {
      const response = JSON.parse(event.data);
      const coordinatesRetrieved = JSON.parse(response);

      console.log(`TRIGGERED! New Spec: ${movementSpec}`);

      // Update State of x and y coordinates
      positionDispatch({
        type: 'SET_POSITION',
        payload: coordinationGenerator(
          {
            rotation: coordinatesRetrieved.ABS_X,
            seesaw: coordinatesRetrieved.ABS_Y,
          },
          movementSpec
        ),
      });
    },
    [movementSpec]
  );

  return (
    <div>
      <p>{movementSpec}</p>
    </div>
  );
};

export default Websocket;

更改Mac 上movementSpecuseCallback功能时,会更新并将“TRIGGERED!...”文本打印到控制台,但在 RaspberryPi 上这不起作用。奇怪的是,段落中的文本在两台机器上都会更新。实际上,除此之外的其他一切都useCallback以完全相同的方式工作!

我尝试了很多不同的东西,但没有落后。任何想法可能是这个问题的根源?任何帮助表示赞赏!

4

0 回答 0