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

<!--- PROPS --> not caught with styled-components HOC #131

Closed
semoal opened this issue Mar 16, 2019 · 8 comments
Closed

<!--- PROPS --> not caught with styled-components HOC #131

semoal opened this issue Mar 16, 2019 · 8 comments

Comments

@semoal
Copy link

semoal commented Mar 16, 2019

Hi!!

I'm using on some components withTheme() HOC from styled-components, actually this addon can't get the props table working with it.

export default withTheme(TextField);

Captura de pantalla 2019-03-16 a las 19 18 38

export default TextField;

Captura de pantalla 2019-03-16 a las 19 19 08

Thanks!

@tuchk4 tuchk4 added the bug label Mar 16, 2019
@tuchk4
Copy link
Owner

tuchk4 commented Mar 16, 2019

exported component should be with defined propTypes.

withTheme should copy propTypes automatically..
In other cases use hoist-non-react-statics

This should work:

import React from 'react';
import PropTypes from 'prop-types';
import styled, { withTheme } from 'styled-components';

const Button = styled.button`
`;

Button.propTypes = {
  label: PropTypes.string.isRequired,
  onClick: PropTypes.func,
  variant: PropTypes.oneOf(['success', 'warning', 'alert']),
};

export default withTheme(Button);

This also will work:

import React from 'react';
import PropTypes from 'prop-types';
import styled, { withTheme } from 'styled-components';

const Button = styled.button`
`;


const ButtonWithTheme =  withTheme(Button);

ButtonWithTheme.propTypes = {
  label: PropTypes.string.isRequired,
  onClick: PropTypes.func,
  variant: PropTypes.oneOf(['success', 'warning', 'alert']),
};

export default ButtonWithTheme;

This will NOT work:

import React from 'react';
import PropTypes from 'prop-types';
import styled, { withTheme } from 'styled-components';

const Button = styled.button`
`;

Button.propTypes = {
  label: PropTypes.string.isRequired,
  onClick: PropTypes.func,
  variant: PropTypes.oneOf(['success', 'warning', 'alert']),
};

export default props => <Button {...props} />;

@semoal
Copy link
Author

semoal commented Mar 16, 2019

Actually I’m doing the first one and it doesn’t work mate.

@tuchk4
Copy link
Owner

tuchk4 commented Mar 16, 2019

I made some local tests and everything is ok with "styled-components": "^4.1.3"

What version of styled-components?

@semoal
Copy link
Author

semoal commented Mar 16, 2019

I’m out home but I guess it’s yours version. Latest stable.

The only difference I remember(later I’ll check it better), is I’m using default props too but damn it the code is almost the same. (All speaking from memory)

@tuchk4 tuchk4 added cant reproduce and removed bug labels Mar 16, 2019
@tuchk4
Copy link
Owner

tuchk4 commented Mar 16, 2019

released example https://tuchk4.github.io/storybook-readme/?path=/story/propstable--button with withTheme
Here is sources https://github.com/tuchk4/storybook-readme/blob/master/packages/example-react/components/Button/index.js

Please try [email protected] and if faced again would be perfect to push repo with reproduction the issue.

@semoal
Copy link
Author

semoal commented Mar 20, 2019

Valerii have you tried my proposal?

@tuchk4
Copy link
Owner

tuchk4 commented Mar 28, 2019

Sorry for long reply. See error now.

I would like to link this issue with #137 because of errors around the same problem.

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

2 participants