Documentation request

babakness
创建于
2018-04-25 05:16:42

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>
  ) 
)
3条回答
babakness
回复于
2018-04-25 08:39:47
#1

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.

gaearon
回复于
2018-04-25 10:30:08
#2

Could you please file this in https://github.com/reactjs/reactjs.org? That’s the documentation repo.

babakness
回复于
2018-04-25 10:39:35
#3

Done

当前位于第1页,总计3 条回复

推荐相似问题

When unmounting a Fragment node, it's children are removed from the DOM one at a time instead of all at once

Do you want to request a feature or report a bug? Bug (maybe! - or perhaps it's just a limitation of Fragments - let me
讨论数 4
react
创建时间:2018-04-24 23:54:56

Build Failing with: 'Error: Cannot find module 'react/src/ReactCurrentOwner'

Do you want to request a feature or report a bug? report a bug What is the current behavior? I've cloned the repo onto m
讨论数 4
react
创建时间:2018-04-24 16:02:20

"Undefined variable: performance" in react-dom for Opera Mini browsers

Do you want to request a feature or report a bug? bug What is the current behavior? When loading babel-polyfill before r
讨论数 4
react
创建时间:2018-04-24 12:52:02

Passing all props from a parent to children looks screwed up

Do you want to request a feature or report a bug? I guess a bug. What is the current behavior? I want to wrap children i
讨论数 4
react
创建时间:2018-04-24 10:48:16

Could hydrate stop modify the content of component, just binding events?

Since my web application run PHP server as backend, I cannot use ReactDOMServer. With lots of restrictions and conventio
讨论数 2
react
创建时间:2018-04-24 10:11:52

`TypeError: 'undefined' is not a function (evaluating 'n.startsWith(e)')` & `React` & `AntD`

TypeError: 'undefined' is not a function (evaluating 'n.startsWith(e)') & React & AntD report a bug? TypeError: 'undefin
讨论数 13
react
创建时间:2018-04-24 06:22:01

validateDOMNesting incorrectly validates table children

Do you want to request a feature or report a bug? bug What is the current behavior? validateDOMNesting shows warning whe
讨论数 2
react
创建时间:2018-04-24 05:30:14

Duplicated key in list has strange behavior!

I have a list which has duplicated items. From the document, key must be unique, but I'm not sure why React concatenates
讨论数 2
react
创建时间:2018-04-24 01:44:26

Improve warning message for failure to initialize `state` when using `getDerivedStateFromProps`

Do you want to request a feature or report a bug? bug What is the current behavior? The warning for a failure to initial
讨论数 5
react
创建时间:2018-04-23 15:29:28

Cannot detect any clicks on elements inside google map infowindow; React

I have created a div element inside a google map infowindow using reactDomServer.renderToString and am trying to registe
讨论数 3
react
创建时间:2018-04-22 09:34:12