react-structured-data icon indicating copy to clipboard operation
react-structured-data copied to clipboard

Unable to conditionally render child components

Open dan-fein opened this issue 6 years ago • 4 comments

Describe the bug I understand this has been touched on in the past, but it's still occurring in .13.

When generating content and rendering it via {variableName}, the content does not render and yields: ** **

To Reproduce Steps to reproduce the behavior:

<JSONLD>
              <Generic type="thing" jsonldtype="Thing" schema={{ url: link, image, description: overview, name }} />
              {products}
</JSONLD>

where products is an array generated like:

var products = []
for(var i = 0; i < itemCount; i++){
      let product = (<Product>
            <AggregateRating ratingCount={ratingCount} bestRating={bestRating} worstRating={worstRating} ratingValue={ratingValue} reviewCount={reviewCount}  />
      </Product>)
      products.push(product)
}

Expected behavior This should render out all of the <Product> components.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Chrome
  • Version 75

Additional context I did notice a few tickets from February saying this was handled, the bug has resurfaced.

dan-fein avatar Jul 12 '19 05:07 dan-fein

Hi use separate <JSONLD> for each product

Describe the bug I understand this has been touched on in the past, but it's still occurring in .13.

When generating content and rendering it via {variableName}, the content does not render and yields: ** **

To Reproduce Steps to reproduce the behavior:

<JSONLD>
              <Generic type="thing" jsonldtype="Thing" schema={{ url: link, image, description: overview, name }} />
              {products}
</JSONLD>

where products is an array generated like:

var products = []
for(var i = 0; i < itemCount; i++){
      let product = (<Product>
            <AggregateRating ratingCount={ratingCount} bestRating={bestRating} worstRating={worstRating} ratingValue={ratingValue} reviewCount={reviewCount}  />
      </Product>)
      products.push(product)
}

Expected behavior This should render out all of the components.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Chrome
  • Version 75

Additional context I did notice a few tickets from February saying this was handled, the bug has resurfaced.

buzjuka avatar Jul 14 '19 12:07 buzjuka

sorry i don't understand, what do you mean use separate? Use separate what?

dan-fein avatar Jul 24 '19 20:07 dan-fein

I am having this issue as well:

TypeError: Cannot read property 'children' of undefined

<JSONLD>
    <Generic type="event" jsonldtype="Event" schema={{
                name,
                eventAttendanceMode: "https://schema.org/OfflineEventAttendanceMode",
                eventStatus: "https://schema.org/EventScheduled",
                description,
                startDate: moment(startDateMS).format("YYYY-MM-DD[T]HH:mm:ss"),
                endDate: moment(endDateMS).format("YYYY-MM-DD[T]HH:mm:ss")
            }}>
                {
                    items.map(({ name, price }) => {
                        return (
                            <Generic type="offers" jsonldtype="Offer" schema={{
                                name,
                                url: "https://shop.klappert.nl/s/" + slug,
                                price,
                                priceCurrency: "EUR",
                            }} />
                        )
                    })
                }
                <Generic type="location" jsonldtype="Place" schema={{ address: postalCode, name: location }} />
            </Generic>
        </JSONLD>

JaapWeijland avatar Apr 10 '20 14:04 JaapWeijland

I am having this issue as well:

TypeError: Cannot read property 'children' of undefined

<JSONLD>
    <Generic type="event" jsonldtype="Event" schema={{
                name,
                eventAttendanceMode: "https://schema.org/OfflineEventAttendanceMode",
                eventStatus: "https://schema.org/EventScheduled",
                description,
                startDate: moment(startDateMS).format("YYYY-MM-DD[T]HH:mm:ss"),
                endDate: moment(endDateMS).format("YYYY-MM-DD[T]HH:mm:ss")
            }}>
                {
                    items.map(({ name, price }) => {
                        return (
                            <Generic type="offers" jsonldtype="Offer" schema={{
                                name,
                                url: "https://shop.klappert.nl/s/" + slug,
                                price,
                                priceCurrency: "EUR",
                            }} />
                        )
                    })
                }
                <Generic type="location" jsonldtype="Place" schema={{ address: postalCode, name: location }} />
            </Generic>
        </JSONLD>

yes it is weird you have to wrap this condition in another generic collection

<GenericCollection>
{
                    items.map(({ name, price }) => {
                        return (
                            <Generic type="offers" jsonldtype="Offer" schema={{
                                name,
                                url: "https://shop.klappert.nl/s/" + slug,
                                price,
                                priceCurrency: "EUR",
                            }} />
                        )
                    })
                }
</GenericCollection>

and this is problem because in console i have warning: Invalid prop 'jsonldtype' of type 'array' supplied to 'ChildNode', expected 'string'

Majrons avatar May 08 '20 12:05 Majrons