Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when inspecting certain Memo component via ReactDevTools #20

Closed
ljosberinn opened this issue Apr 15, 2019 · 2 comments
Closed

Error when inspecting certain Memo component via ReactDevTools #20

ljosberinn opened this issue Apr 15, 2019 · 2 comments

Comments

@ljosberinn
Copy link

As soon as I click this memoized component

2019-04-15 11_24_16-DevTools - localhost_3000_hqplanner

whyDidYouRender crashes while trying to load Hooks:
2019-04-15 11_28_50-DevTools - localhost_3000_hqplanner

2019-04-15 11_22_12-Resources Helper
2019-04-15 11_22_30-DevTools - localhost_3000_

Is this an issue on my side? I don't have this problem with other memoized Hooks-using components, only on this specific one.

@htshah
Copy link

htshah commented Apr 29, 2019

I have exact same issue..
Anyone can help us out...

Code

import React, { useCallback, memo, useRef } from "react";
import { Grid, Button } from "@material-ui/core";

import { useApp } from "../../context/App";
import JoystickContainer from "./component/JoystickContainer";

const HomeScreen = () => {
  const { isConnected, setConnected } = useApp();
  // const [isConnected, setConnected] = useState(false);

  const stickPositionRef = useRef({
    throttle: 0,
    yaw: 0,
    pitch: 0,
    roll: 0
  });

  const setStickPosition = newPosition => {
    stickPositionRef.current = { ...stickPositionRef.current, ...newPosition };
  };

  const handleConnection = () => {
    setConnected(!isConnected);
  };

  const onLeftStickMove = ({ x, y }) =>
    setStickPosition({ throttle: -y, yaw: x });
  const onLeftStickEnd = () => setStickPosition({ yaw: 0 });

  const onRightStickMove = ({ x, y }) =>
    setStickPosition({ pitch: -y, roll: x });
  const onRightStickEnd = () => setStickPosition({ pitch: 0, roll: 0 });
  return (
    <React.Fragment>
      <Grid
        container
        direction="column"
        justify="space-between"
        alignItems="stretch"
        style={{ height: "40%" }}
      >
        <Grid item style={{ height: "30px" }}>
          Grid 1.1
        </Grid>
        <Grid item>Grid 1.2</Grid>
      </Grid>
      {/* Joystick render */}
      <JoystickContainer
        onLeftStickMove={useCallback(onLeftStickMove, [])}
        onLeftStickEnd={useCallback(onLeftStickEnd, [])}
        onRightStickMove={useCallback(onRightStickMove, [])}
        onRightStickEnd={useCallback(onRightStickEnd, [])}
      />

      <Grid
        container
        justify="center"
        style={{ height: "20%", padding: "10px 0" }}
      >
        <Grid item>
          <Button
            variant="contained"
            color="primary"
            onClick={handleConnection}
          >
            {isConnected === false ? "Connect" : "Disconnect"}
          </Button>
        </Grid>
      </Grid>
    </React.Fragment>
  );
};
HomeScreen.whyDidYouRender = true;

export default memo(HomeScreen);

@vzaidman
Copy link
Collaborator

fixed in v3.0.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants