Skip to content

Instantly share code, notes, and snippets.

@Surajkamdi
Forked from granmoe/ React Join Children
Created March 4, 2020 05:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Surajkamdi/98d80514b1cdcc181d97e68abeac5e4a to your computer and use it in GitHub Desktop.
Save Surajkamdi/98d80514b1cdcc181d97e68abeac5e4a to your computer and use it in GitHub Desktop.
Ever wanted to join react children like you join an array?
This file is only here to provide the title of the gist
import React from 'react'
import joinChildren from 'react-join-children'
import { Item, Separator } from 'justanexample'
export default class MyComponent extends React.Component {
render () {
return <div>
{ joinChildren(this.props.items, this.renderItem, this.renderSeparator) }
</div>
// with 3 items, joinChildren returns [<Item>, <Separator>, <Item>, <Separator>, <Item>]
}
renderItem = (item, index) => {
return <Item key={ index } className="item" />
}
renderSeparator = key => {
return <Separator className="separator" key={ key } />
}
}
export default function (children, render, renderSeparator) {
return children.reduce((result, child, index) => {
if (index < children.length - 1) {
return result.concat([render(child, index), renderSeparator(index + '-separator')])
}
return result.concat(render(child, index))
}, [])
}
@partyush
Copy link

partyush commented Oct 14, 2022

Hi, I have read your blog, Its Amazing do you have a dummy project with react integration I want to look at its features and process for the understanding of AEM, I am a beginner in AEM.

Any help will be appreciated

thanks

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