TheSpicyMeatball / react-nanny

Utils to manage your React Children
Other
85 stars 4 forks source link

Warning: React does not recognize the `__TYPE` prop on a DOM element #2

Closed kozlikov closed 3 years ago

kozlikov commented 3 years ago

Hello!

Unfortunately, the reagent issues an inconvenient warning and is very annoying when developing if additional other errors or warnings appear.

Warning: React does not recognize the `__TYPE` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `__type` instead. If you accidentally passed it from a parent component, remove it from the DOM element.

It would be great if we fix this behavior...

TheSpicyMeatball commented 3 years ago

@kozlikov react-nanny doesn't add any props to any components so I'm guessing that you might have it bleeding through a rest prop.

Where your component is possibly something like this:

import React from 'react';

const Hello = ({ ...other }) => <div {...other}>Hello World!</div>;

Hello.defaultProps = {
  __TYPE: 'Hello',
};

Where it should be something like this:

import React from 'react';

const Hello = ({ __TYPE, ...other }) => <div {...other}>Hello World!</div>;

Hello.defaultProps = {
  __TYPE: 'Hello',
};

(notice that __TYPE is an unused constant not included in the render)

Let me know if that helps. Otherwise, if you could post some code of your usage, I'd be more than happy to take a look.

kozlikov commented 3 years ago

@TheSpicyMeatball Yes, of course, please, here's an example in the codebox:

https://codesandbox.io/s/exmaple31212020-whkt8?file=/src/App.js

P.S. Perhaps this is due to the new version of react.

image

TheSpicyMeatball commented 3 years ago

Change this line (line #6)...

const { children, ...other } = props;

To this...

const { children, __TYPE, ...other } = props;

That will keep __TYPE from ending up in your DOM.

kozlikov commented 3 years ago

Oh, with this react, that I already forgot about the default html tags and their parameters))

Thank you very much!!!

TheSpicyMeatball commented 3 years ago

You got it!