question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

customInput failed prop type with styled-component passed

See original GitHub issue

Hi, sorry but I got this error when I try to pass a styled-component

import styled from 'styled-components';

const StyledInput = styled((props) => (
  <input {...props} />
))`
  // my stylings...
`

to the customInput prop. The error that I got is the following

Failed prop type: Invalid prop customInput of type object supplied to NumberFormat, expected function.

However the app works just fine. What’s the cause of this if I may get a better understanding? Thank you in advance!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
blaipratcommented, Apr 21, 2019

Had the same issue, but after changing the prop to a function wrapper seems to be workign as expecteed. The code that works:

<NumberFormat
    type="text"
    value={value}
    customInput={(props) => <StyledInput {...props} />}
/>

Update: Seems that after applying this only the first key is registered, so still not working as expected

1reaction
alextileycommented, May 11, 2019

I have created a pull request which fixes this - the function prop-type is not quite correct and can now be replaced with PropTypes.elementType. As a temporary workaround it’s possible to suppress the prop-type warning by wrapping your styled-component in a class component, e.g:

const StyledInput = styled.input`
  // Your styles
`;

class Input extends React.Component {
  render() {
    return (
      <StyledInput {...this.props} />
    );
  }
}

This is not ideal but is another solution for those who stumble upon this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Number Format and Styled Components - props getting ...
Turned out React Number Format has a similar prop called customInput so the solution I found is doing it this way <NumberFormat customInput={ ......
Read more >
Basics - styled-components
You can pass a function ("interpolations") to a styled component's ... Note how the inputColor prop is not passed to the DOM, but...
Read more >
Complete Guide On How To Use Styled-components In React
You must pass in the className prop in the parent element of the component to be styled because with it styled component can...
Read more >
[Solved]-Styled Component For Forms-Reactjs
Coding example for the question Styled Component For Forms-Reactjs. ... name="email" helperText={touched.email ? errors.email : ''} error={touched.email ...
Read more >
Deciphering TypeScript's React errors | by Fiona Hopkins |
Getting a prop's type wrong, such as passing a string when it expects a number. If we write these bugs, TypeScript will show...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found