question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The playground component seems to affect the child component type

See original GitHub issue

Bug Report

When using the <Playground> component, you cannot check the type of the children within the component.

For example, say I have two components - Chip and ChipCloud. If in the render method of the ChipCloud you have something like:

// import the chip class for checking
import Chip from '../Chip'

// in the render method
React.Children.map(this.props.children, child => {
    if(child.type === Chip) {
        return React.cloneElement(child, {
            theme: this.props.theme 
        })
    } else {
        return child
    }
})

Basically, my use case is that if a Chip is the child of a ChipCloud, the ChipCloud can override certain props IF the child is a Chip and other children that aren’t of the Chip type should be rendered as usual.

The line if(child.type === Chip) does not work when run within the Playground component. Not sure if it modifies the type of its children during render or clones them or what, but it affects that check.

Here is a link to a repo where the above works as expected:

https://codesandbox.io/s/mjp6zzwxjj

Expected behavior

The Playground component should affect the type of the children during render. I would expect that the same behavior in the example above occur in the Playground component.

Enviroment

  • OS: Windows 10
  • Node/npm version: v8.9.3 / v5.5.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tsnolan23commented, Jul 14, 2018

Granted, the official prop-types docs show usage of:

PropTypes.instanceOf(Component)

https://github.com/facebook/prop-types/blob/master/README.md#usage

1reaction
tsnolan23commented, Jul 12, 2018

@pedronauck Here is the reproducible example!

https://github.com/tsnolan23/docz-children-type-issue

Let me know if you have any questions with where the issue is or how it’s set up

Read more comments on GitHub >

github_iconTop Results From Across the Web

Child component attribute updates break when using ... - GitHub
1.3 to reproduce a working version in the SFC playground as there appears to be an API change between v3.1.3 and v3.1.5 which...
Read more >
How Playgrounds Can Impact Cognitive Development | LTC
Learn about the way that Playgrounds can impact cognitive development in children and why cognitive development is so important. Read now!
Read more >
How Do the Children Play? The Influence of Playground Type ...
Children demonstrated higher levels of associative and cooperative play on the school playground, but higher levels of solitary and parallel ...
Read more >
React 18 TypeScript children FC - Stack Overflow
Today it seems every single component that uses children is throwing an error. Property 'children' does not exist on type 'IPageProps'.
Read more >
Benefits of Playground Equipment - Landscape Structures
The study suggests that different playground components facilitate different patterns of play and therefore reinforce different developmental skills. In the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found