Skip to content

React.Children.only expected to receive a single React element child #19

Description

@jefffriesen

If you try to recreate the example in the README, you get this error:

React.Children.only expected to receive a single React element child

The problem is that <Step> is taking text nodes in the example:

        <Scrollama onStepEnter={this.onStepEnter}>
          <Step data={1} key='1'>
            step 1
          </Step>
          <Step data={2} key='2'>
            step 2
          </Step>
        </Scrollama>

However, if you replace the text nodes any element, then everything works correctly:

        <Scrollama onStepEnter={this.onStepEnter}>
          <Step data={1} key='1'>
            <div>step 1</div>
          </Step>
          <Step data={2} key='2'>
            <div>step 2</div>
          </Step>
        </Scrollama>

React.Children.only(children) throws with a text node: https://github.com/jsonkao/react-scrollama/blob/master/src/Step.js#L25

I don't know if you want to allow text nodes, or update the README to wrap the text in elements.

Metadata

Metadata

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions