React-window: data prop in children props is undefined

Created on 11 Oct 2018  路  2Comments  路  Source: bvaughn/react-window

When I log the children component props,

const Row = (props) => {
  console.log('-----', props)
  return (
    <div>#{props.index}</div>
  )
}

image

the data prop in props is undefined, why an undefined value is passed to the children component?

Here is the source code

// ...
        createElement(children, {
              data: itemData,
              key: itemKey(index),
              index,
              isScrolling: useIsScrolling ? isScrolling : undefined,
              style: this._getItemStyle(index),
         })

// ...

The itemData is from the props.

馃挰 question

Most helpful comment

props.data will be whatever you pass as itemData to the list (as mentioned in the docs) 馃槃

class ComponentThatRendersAListOfItems extends PureComponent {
  render() {
    // Pass items array to the item renderer component as itemData:
    return (
      <FixedSizeList
        itemData={this.props.itemsArray}
        {...otherListProps}
      >
        {ItemRenderer}
      </FixedSizeList>
    );
  }
}

// The item renderer is declared outside of the list-rendering component.
// So it has no way to directly access the items array.
class ItemRenderer extends PureComponent {
  render() {
    // Access the items array using the "data" prop:
    const item = this.props.data[this.props.index];

    return (
      <div style={this.props.style}>
        {item.name}
      </div>
    );
  }
}

All 2 comments

props.data will be whatever you pass as itemData to the list (as mentioned in the docs) 馃槃

class ComponentThatRendersAListOfItems extends PureComponent {
  render() {
    // Pass items array to the item renderer component as itemData:
    return (
      <FixedSizeList
        itemData={this.props.itemsArray}
        {...otherListProps}
      >
        {ItemRenderer}
      </FixedSizeList>
    );
  }
}

// The item renderer is declared outside of the list-rendering component.
// So it has no way to directly access the items array.
class ItemRenderer extends PureComponent {
  render() {
    // Access the items array using the "data" prop:
    const item = this.props.data[this.props.index];

    return (
      <div style={this.props.style}>
        {item.name}
      </div>
    );
  }
}

Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carolin913 picture carolin913  路  3Comments

bnikom picture bnikom  路  3Comments

migueloller picture migueloller  路  3Comments

jsu93 picture jsu93  路  4Comments

lifeisaloha picture lifeisaloha  路  3Comments