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

Fix Switch component not matching/rendering nested array children correctly #1441

Merged
merged 1 commit into from Jan 30, 2019

Conversation

jnnnik
Copy link
Contributor

@jnnnik jnnnik commented Jan 30, 2019

Objective

This PR introduces a change to the way a Switch handles its child components, allowing for (nested) array children to sit next to regular component children.

A rough example of this would be the following:

<Switch>
  { topics.map(topic =>
    <Route exact path={`/${topic.alias}`}><SomeComponent topic={topic} /></Route>) }
  <Route component={NotFound} />
</Switch>

Before this fix, this construct would result in a TypeError: Cannot read property 'path' of undefined.

See the added tests in Switch.spec.jsx for more examples.

When moving the child handling into a separate function, I have left the naming intact from the existing implementation, as this is my first attempt at contributing to this awesome project and I didn't want to rummage around too much. I'm always happy about feedback!

…rectly

Switch rendering previously correctly treated multiple children, however it failed to process nested arrays, such as the result of an Array.prototype.map(...) call next to a regular child component
@coveralls
Copy link
Collaborator

Coverage Status

Coverage increased (+0.008%) to 94.975% when pulling 8b3b5d9 on jnnnik:master into 064d6bd on infernojs:master.

@Havunen
Copy link
Member

Havunen commented Jan 30, 2019

Hi @jnnnik thanks for the PR.

The change looks good to me, lets merge it! :-)

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

Successfully merging this pull request may close these issues.

None yet

3 participants