Immutable.js 맵을 반복 처리하여 구성 요소를 렌더링하려고합니다. 렌더링 중이지만 페이지의 키도 렌더링합니다. 왜 그런지 모르겠습니다.React 16 맵 렌더링 키를 반복합니다.
render() {
const myMap = new Map({foo: '', bar: 'http://google.com/'})
const {showFoo, titleAndUrl} = this.props
return (
<ul style={[
styles.container,
showFoo && styles.container.inline,
]}>
{myMap.map((title, url) => this.renderTab(url, title))}
</ul>
)
}
renderTab(title, url) {
const {showFoo, isFoo} = this.props
return (
<li key="sb" style={[
styles.listItem,
showFoo && styles.listItem.inline,
]}>
<a
href={url}
key={title}
style={[
styles.link,
styles.activeLink,
showFoo && styles.link.inline,
]}
className={isFoo ? "style" : ''}>
{title}
</a>
</li>
)
}
}
두 개의 이름과 URL은 그러나 키가 렌더링 즉 foo는 두 번 렌더링되는 중복 등 바이지만, foo는 바 키 중 하나가 외부 렌더링되고있어 어떤 제안, 어떤 스타일이 없습니다 올바르게 렌더링됩니다 this.renderTab
렌더링 된 HTML :
<ul data-radium="true"
style="display: flex; align-items: center; padding: 0px; margin: 0px; list-style: none; width: 100%; border-top: 1px solid rgb(221, 221, 221); height: 48px;">
foo
<li data-radium="true" style="display: flex; width: 50%; height: 47px; cursor: default;"><a href=""
class=""
data-radium="true"
style="display: flex; justify-content: center; align-items: center; width: 100%; text-decoration: none; font-weight: 500; font-size: 16px; color: rgb(0, 31, 91); transition: color 0.1s linear;">foo</a>
</li>
bar
<li data-radium="true" style="display: flex; width: 50%; height: 47px; cursor: default;"><a
href="http://google.com" class="" data-radium="true"
style="display: flex; justify-content: center; align-items: center; width: 100%; text-decoration: none; font-weight: 500; font-size: 16px; color: rgb(0, 31, 91); transition: color 0.1s linear;">bar</a>
</li>
</ul>
'지도, 그것은 요소를 단지 루프는하지 않습니다. 이것은 몇 가지 이유와 관련이있을 수 있습니다. 그러나 전체 구성 요소가 아닌 키를 반환하는 이유가 확실하지 않습니다. – Y2H