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.

PropsChildren's type isn't exactly Array

See original GitHub issue

I have a component that can pass children nodes which can be empty:

object Hello {
  private val ComponentName = this.getClass.getSimpleName

  private case class Props(message: String)

  private case class Backend(scope: BackendScope[Props, _]) {
    def render(P: Props, C: PropsChildren): vdom.ReactTagOf[Div] = {
      println(C)
      // If C is empty then render an empty div
      if (C.isEmpty) {
        <.div()
      } else {
        <.div(^.cls := "message", 
          C,
          P.message
        )
      }
    }
  }

  private val component = ReactComponentB[Props](ComponentName)
    .stateless
    .renderBackend[Backend]
    .build

  def apply(message: String)(children: ReactNode*): ReactComponentU[_, _, _, TopNode] = {
    component(Props(message), children: _*)
  }
}

My attempt to use is

Hello("message here")() // Is this correct way to pass an empty child?
Hello("message here")(<.div("Children"))

It compiles successfully, but when loading the page on browser, I got the exception for the 1st usage (Hello("message here")()):

issue

I added println(C) inside the Backend.render() method, and I got undefined when calling (Hello("message here")()).

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
japgollycommented, Jun 10, 2016

This will be fixed as part of #259.

0reactions
japgollycommented, Aug 20, 2016

Fixed on topic/neo branch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is `this.props.children` not an array when there's just one ...
It makes it more difficult to work with when you have to take account that it may sometimes be a single child and...
Read more >
Questions regarding "props.children" · Issue #12913 - GitHub
Why exactly isn't props.children in case there are some children (one ore more) just always an array (as it is done in "Preact"...
Read more >
Find & Filter React Children By Type - Michael Paravano
This article will discuss the how-it-works for finding and filtering React children by type as it pertains to custom component children.
Read more >
A deep dive into children in React - Max Stoibers Blog
What they are essentially telling us is that props.children can be any type, such as an array, a function, an object, etc.
Read more >
Typechecking With PropTypes - React
import PropTypes from 'prop-types'; class Greeting extends React. ... must be exactly one element or it will warn. const children = this.props.children; ...
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