Skip to content

Instantly share code, notes, and snippets.

@meddokss
Last active March 20, 2024 08:34
Show Gist options
  • Save meddokss/009cdb5192e487654c0d90cd8f692214 to your computer and use it in GitHub Desktop.
Save meddokss/009cdb5192e487654c0d90cd8f692214 to your computer and use it in GitHub Desktop.
[Styled-components Error] Warning: React does not recognize the prop on a DOM element. #STYLED
Warning: React does not recognize the `isEditing` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `isediting` instead. If you accidentally passed it from a parent component, remove it from the DOM element.
    in button (created by ForwardRef(Tab))
    in ForwardRef(Tab) (created by Context.Consumer)
    in StyledComponent (created by Styled(Component))
    in Styled(Component) (at App.js:14)

In the TextBox component you're passing all the props from the parent via {...props}. Considering that TextField itself doesn't have 'isEditing' property, I assume it passes it down to the underlying input DOM element, which doesn't recognise that prop.

What you can do is to extract the props used inside TextBox and collect the rest using the rest argument, so you don't end up passing unnecessary props down:

*FOR WRAPPED COMPONENTS*

const {isEditing,  ...args} = props;
OR
export default function TextBox({isEditing,  ...props}) {
	//isEditing usage
	return <TextField {...props}/>
};

*FOR STYLED-COMPONENTS*

const TextBox = styled(({ isEditing, ...props }) => <TextField {...props} />)`
  visibility: ${(props) => (props.isEditing ? "visible" : "hidden")};
  flex-direction: row;
  width: 100%;
`;

*FOR STYLED-COMPONENTS v5.1+ *

Those coming from Google, in styled-components you have to rename your props to start with $, and you need to be on 5.1+. https://styled-components.com/docs/api#transient-props

const TextBox = styled(TextField)`
  visibility: ${(props) => (props.$isEditing ? "visible" : "hidden")};
  flex-direction: row;
  width: 100%;
`;
<TextBox
  $isEditing={isEditing}
  id="standard-name"
  label="Update title"
  value={name}
  onChange={onChangeHandler}
  fullWidth
  multiline
  rowsMax={4}
/>
@volodalexey
Copy link

Thanks!

@ZeldOcarina
Copy link

I'm coming from Google, thanks a lot!! :)

@kamo93
Copy link

kamo93 commented Apr 11, 2023

Thanks 👏🏼

@alexrabin
Copy link

Thank you!

@groverjatin17
Copy link

Thank you. Came from Google as well. 🚀

@sousakan
Copy link

Thanks!

@dtsao
Copy link

dtsao commented May 30, 2023

Thanks! (from Google)

@mo-fouad
Copy link

anyway not to use the $
or to get around it ?! :D

@mo-fouad
Copy link

@HereOrCode
Copy link

Thanks!

@franklin-01
Copy link

Thanks!

@chimaris
Copy link

It helps. Thanks

@mateusmoura
Copy link

Thanks!! 💡🚀

@rodrigo-miranda18
Copy link

Is there any codemod that does this job automatically?

@ZeldOcarina
Copy link

Not that I know of, it's so bad to refactor a huge codebase that it made me migrate out of styled components haha

@rodrigo-miranda18
Copy link

Same here! Actually I'd like to suppress this error temporarily, just because I'll migrate to Tailwind in the near future. I think downgrade to v5 is the best option for now.

@pro-frontend
Copy link

Thanks, it works!

@a-hariti
Copy link

Thanks

@fs-engineer
Copy link

Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment