reactjs / reactjs/react.dev

Please document how to reference a list of items

Open
#841 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

Please document how to use forwardRef (the preferred way) to retrieve a list or array of items. For example,

const foo = React.forwardRef( (props,ref) => 
  props.superHeros.map( 
    ( hero, index) => <li ref={  ref  } key={ index }>{ hero }</li>
  ) 
)


Perhaps the key question here is, why not do this?

componentDidMount(){
  const foo = this.refs.root.querySelector('.foo')
  ...
}

Suppose there are 50,000 className='foo' elements that are returned by an embedded component. Is this code not portable? Is this code slower than having 50,000 ref created?

Please document this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the forwardRef example in the issue and compare it with the componentDidMount/querySelector approach. Document how to reference a list or array of items, including the portability and performance questions raised about many elements. Done means the preferred approach and its trade-offs are clearly explained.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.