0

I develop a React-Electron-Boilerplate (with Redux) app on my MacBook. Since it needs to run on my RaspberryPi later on, I test it there from time to time. Up to now, everything was identical...

I retrieve coordination via WebSocket and update their global state based on the chosen movementSpec. But somehow, this works differently when running on macOS than on 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;

When changing the movementSpec the useCallback function on the Mac updates and prints the "TRIGGERED! ... " text to the console, but on the RaspberryPi this just does not work. Strangely, the text in paragraph updates on both machines. Actually, everything else besides this useCallback works exactly the same way!

I tried many different things but did not get behind it. Any ideas what could be the root for this problem? Any help appreciated!

M.S.
  • 49
  • 8

0 Answers0