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

Inline conditional rendering Layer causes Source render cloneElement to fail #1135

Closed
123joshuawu opened this issue Jun 21, 2020 · 1 comment
Labels

Comments

@123joshuawu
Copy link

<ReactMapGL>
  { features.map((feature) => (
    <Source>
      <Layer />
      {selected.zoneId === feature.id && <Layer />}
    </Source>
  ) }
</ReactMapGL>

Results in this error
Error: React.cloneElement(...): The argument must be a React element, but you passed null.

I believe it is because in the render for source, the children are iterated over using React.children.map as seen in lines 139 through 142. When the inline conditional is false, the resulting React.children element is null, which is then passed to React.cloneElement.

_render(context: MapContextProps) {
if (!this._map && context.map) {
this._map = context.map;
this._map.on('styledata', this._updateSource);
}
this._updateSource();
return React.Children.map(this.props.children, child =>
cloneElement(child, {
source: this.id
})
);
}

Here is the issue that talks about React.children.map and null values.
facebook/react#4867

I think a possible solution is to use React.children.toArray which will filter out null and undefined values.

@Pessimistress
Copy link
Collaborator

Fixed in 5.2.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants