Skip to content

recursive data #246

@Gregoor

Description

@Gregoor

First off all, love idea and the great talks about it on ReactEurope. But I still get stuck quite a lot (which I should expect from a technical preview). Here is my current problem:

My data is modeled like this:

type Babushka {
  id: !String,
  name: !String,
  babushkas: [Babushka]
}

Now I want to display a Babushka list for which I have a List and a ListItem Component:

list.js

class BabushkaList extends Component {

  render() {
    return <ul>{this.props.babushka.babushkas.map(b => <BabushkaListItem babushka={b}/>)}</ul>;
  }

}

export default Relay.createContainer(BabushkaList, {

  fragments: {
    babushka: () =>  Relay.QL`
      fragment on Babushka {
        babushka {
          ${BabushkaListItem.getFragment('babushka')}
        }
      }
    `
  }

});

list-item.js

class BabushkaListItem extends Component {


  render() {
    return (
      <li onClick={this.onClick.bind(this)}>
        {this.props.babushka.name}
        <ul><BabushkatList babushka={this.props.babushka}</ul>
      </li>
    );
  }

}

export default Relay.createContainer(BabushkaListItem, {

  fragments: {
    babushka: () =>  Relay.QL`
      fragment on Babushka{
        name,
        ${BabushkaList.getFragment('babushka')}
      }
    `
  }

});

Naturally this leads to the stack size being exceeded. Am I doing something wrong fragment wise?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions