-
Notifications
You must be signed in to change notification settings - Fork 17
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
PropTypes error #42
Comments
Hi @brummelte ! This doesn’t appear to be an issue with Composer. Maybe asking the question on StackOverflow is a better place to get help on this question. Best of luck! |
It is an issue with Composer, because the only allowed syntax for the components prop is using an empty component: <Composer components={[<LanguageProvider />, <ThemeProvider />]}> And the prop type validation then fails. The application works, just the prop types fail. One way not to have the console error is wrapping the components, so that the prop types are only checked on render: const wrapComponent = Component => ({ children, ...otherProps }) => (
<Component {...otherProps}>{children}</Component>
);
const LanguageProvider2 = wrapComponent(LanguageProvider);
const ThemeProvider2 = wrapComponent(ThemeProvider);
<Composer components={[<LanguageProvider2 {...languageProps} />, <ThemeProvider2 {...themeProps} />]}> That works, but is not really easy to write. The following is better: <Composer
components={[
<LanguageProvider {...languageProps}>{() => {}}</LanguageProvider>,
<ThemeProvider {...themeProps} >{() => { }}</ThemeProvider>
]}
> Adding a syntax like the following might be a possibility aswell: <Composer
components={[LanguageProvider, ThemeProvider]}
props={[{
...languageProps
}, {
...themeProps
}]}
> If the new syntax (3) is not going to be implemented, maybe adding a note to the readme for using 2 would be a good idea. |
Ah, I see what you mean. I’ll add a note to the README, but I don’t think a new API should be introduced. @erikthedeveloper what do you think? |
Yeah I see what @brummelte is saying. I think it's fairly common to declare As-is, the ideal solution would be to do the suggested option 2 above (#42 (comment)) knowing that <Composer
components={[
<LanguageProvider {...languageProps} children={() => null} />
]}
// ...
> I will point out that the proposed change to the <Composer
components={[
({render}) => <LanguageProvider {...languageProps} children={render} />,
({render}) => <RequiresRender render={render} />
]}
// ...
> |
Thanks for the input, @erikthedeveloper ! I added a guide about this topic to the documentation over in #44 . I also opened a poll about whether or not we should make the breaking API described by #39 over in #43 . |
Hi again @brummelte ! It is looking like people are liking the API over in #43 , so this issue will have a really good solution once we merge and deploy that change ( #39 ). I am currently planning to do that release this weekend. Thank you for opening this issue! I hope you find this solution acceptable ✌️ |
Yes, thanks. That change is great. |
I’m glad you like it! It has been released as v5.0.0 ✌️ |
Having render prop components with propTypes will result in console errors:
https://codesandbox.io/s/r1ywymx0kn
The text was updated successfully, but these errors were encountered: