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

Cannot wrap FallbackComponent with styled components #61

Closed
schabluk opened this issue Jul 22, 2020 · 4 comments · Fixed by #62
Closed

Cannot wrap FallbackComponent with styled components #61

schabluk opened this issue Jul 22, 2020 · 4 comments · Fixed by #62
Labels

Comments

@schabluk
Copy link

  • react-error-boundary version: 2.3.0
  • node version: 12.16.1
  • npm version: 6.13.4

Relevant code or config

const ErrorFallbackTop: React.FC<ErrorFallbackProps> = ({
  error: { message },
  className,
}): JSX.Element => {
  return (
    <div className={className}>
      <div>{message}</div>
    </div>
  );
};

export default styled(ErrorFallbackTop)`
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
`;

What you did: wrapped FallbackComponent in styled-components styled() method.

What happened:

react-error-boundary.umd.js?e895:109 Uncaught (in promise) Error: react-error-boundary requires either a fallback, fallbackRender, or FallbackComponent prop
    at ErrorBoundary.render (react-error-boundary.umd.js?e895:109)
    at finishClassComponent (react-dom.development.js?61bb:17160)
    at updateClassComponent (react-dom.development.js?61bb:17110)
    at beginWork (react-dom.development.js?61bb:18620)
    at HTMLUnknownElement.callCallback (react-dom.development.js?61bb:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js?61bb:237)
    at invokeGuardedCallback (react-dom.development.js?61bb:292)
    at beginWork$1 (react-dom.development.js?61bb:23203)
    at performUnitOfWork (react-dom.development.js?61bb:22154)
    at workLoopSync (react-dom.development.js?61bb:22130)
@kentcdodds
Copy link
Collaborator

Thanks for this. Could you make a reproduction in a codesandbox?

@marcosvega91
Copy link
Contributor

I have created this example https://codesandbox.io/s/quiet-fast-g7747?file=/src/App.js

What do you think if we use import {isValidElementType} from 'react-is' instead of check if the FallbackComponent is a function?

@kentcdodds
Copy link
Collaborator

That sounds good to me! Thanks @marcosvega91.

marcosvega91 added a commit to marcosvega91/react-error-boundary that referenced this issue Jul 22, 2020
fix bvaughn#61
To fix the issue I have used the library from facebook 'react-is'.
With this library we can check if the FallbackComponent is a real component.
A component is not alwasy a function, but can be also object
kentcdodds pushed a commit that referenced this issue Jul 23, 2020
* test: add failing tests

* chore: add react-is as dep

* fix: support all kind of component

Closes #61
To fix the issue I have used the library from facebook 'react-is'.
With this library we can check if the FallbackComponent is a real component.
A component is not alwasy a function, but can be also object

* chore: remove react-is dep

* fix: check FallbackComponent if is defined instead of using react-is

* test: simplify test after review
@kentcdodds
Copy link
Collaborator

🎉 This issue has been resolved in version 2.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants