Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Ref does not work on custom components created with applyTheme #71

Closed
MrToph opened this issue Sep 29, 2020 · 3 comments
Closed

Ref does not work on custom components created with applyTheme #71

MrToph opened this issue Sep 29, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@MrToph
Copy link

MrToph commented Sep 29, 2020

React refs do not seem to work correctly on custom components created with applyTheme.
This seems to be because they are a functional component and they don't correctly forwardRef?

I get this error:

Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

To Reproduce

const CustomButton = applyTheme(Button, {
  styles: {
    base: {
      minHeight: "unset",
      whiteSpace: `nowrap`,
    },
  },
  defaultProps: {
    variant: "ghost",
  },
});

const App = () => {
  const buttonRef = useRef(null);
  const handleClick = () => {
    console.log(buttonRef.current) // should be defined
  }
  return (
    <CustomButton onClick={handleClick} ref={buttonRef}>
      Click
    </CustomButton>
  );
};
@jxom
Copy link
Owner

jxom commented Sep 29, 2020

Thanks! I'll have a look into this soon! Maybe use elementRef for now?

@MrToph
Copy link
Author

MrToph commented Oct 1, 2020

Great. I'm not aware of elementRef, I checked the docs of the Button component but couldn't find anything. Can you point me to some description of elementRef.

Edit: It's on Box

@jxom jxom added the bug Something isn't working label Oct 3, 2020
@jxom
Copy link
Owner

jxom commented Oct 3, 2020

This should be fixed on 1.3.8

@jxom jxom closed this as completed Oct 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants