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

childrenOfType incompatible with projects using react-hot-loader #39

Open
liuhelen10 opened this issue Mar 22, 2018 · 2 comments
Open

Comments

@liuhelen10
Copy link

liuhelen10 commented Mar 22, 2018

childrenOfType is currently incompatible with projects using react-hot-loader because of this line:

https://github.com/airbnb/prop-types/blob/master/src/childrenOfType.js#L8

According to the react-hot-loader docs, because React Hot Loader creates proxied versions of your components, comparing reference types of elements won't work. It looks like they provide an areComponentsEqual helper that checks for that (more details here), but I'm not sure if there's a good way to integrate with this.

It looks like there is an open issue on react-hot-loader about this -- curious if you guys have any ideas for a solution or workaround: gaearon/react-hot-loader#304

@ljharb
Copy link
Owner

ljharb commented Mar 23, 2018

Thanks for filing; I’m relatively sure this is just the nature of hot reloading interfering with the referential nature of JS - and i wouldn’t want to use brittle string comparisons, nor depend directly on RHL.

Happy to leave this open while we brainstorm other solutions.

@harrytruong
Copy link

Just noting this (in case it helps anyone who comes across this issue too):


Example:

// `Table` uses `childrenOfType` to assert type `Row` 
import Table, { Row } from '../example/Table';

// leads to a PropTypes validation error, 
// when `react-hot-loader` is enabled:
const Foo = () => {
  return (<Table><Row /></Table>);
}

To fix the issue on a component-by-component basis:

import { cold } from 'react-hot-loader';
import Table, { Row as _Row } from '../example/Table';

// avoids printing false errors in non-production env 
// see https://github.com/airbnb/prop-types/issues/39
const Row = cold(_Row);

// no more PropTypes validation error, 
// when `react-hot-loader` is enabled:
const Foo = () => {
  return (<Table><Row /></Table>);
}

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

3 participants