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

Support styled function components #3

Merged
merged 1 commit into from
Aug 4, 2021

Conversation

finkef
Copy link
Contributor

@finkef finkef commented Aug 4, 2021

When trying to use styled without the string alias like styled("View", ...), but with an actual component like styled(View, ...), I'm getting this error:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports

This is due to a missing check for typeof component === "function". Also, cloneElement is used rather than createElement after the typeof component === "object" check which I assume was to allow using styled for React.memo'ed components already created by styled("View", ...). Note that createElement works with memoized components as well as with any other function or class component.

Copy link
Owner

@Temzasse Temzasse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Looks great, thanks! 👍🏻

@Temzasse Temzasse merged commit e102a99 into Temzasse:main Aug 4, 2021
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

Successfully merging this pull request may close these issues.

3 participants