【发布时间】:2020-06-05 14:48:34
【问题描述】:
我有一个像这样的纯组件?
interface CheckBoxOptions {
multiSelected?: boolean
showOuterCheckBoxOnSelected?: boolean
}
interface Props {
checkBoxKey?: any
itemTitle?: string
isCheckBoxSelected?: boolean
checkBoxStyle?: any
mainContainerStyle?: any
checkBoxTitleStyle?: any
checkBoxBackgroundColor?: any
onPressCheckBox?: (id, isChecked, selectedArray , options?: CheckBoxOptions) => void
itemKey?: any
options?: CheckBoxOptions
}
在这个我需要这个选项界面,因为no可以增加
现在当我在我的 otherComponent 中使用这个 pureComponents 时
renderCheckBoxComponent = (checkBoxKey , checkBoxList ) => {
const totalCheckBoxelements = checkBoxList && checkBoxList.length
log('renderCheckBoxComponent', checkBoxList )
const {onPressChackBox} = this.props
return checkBoxList && checkBoxList.map((item , index) => {
return (
<View style={[ styles.checkBoxContainer , { borderBottomWidth: (index === totalCheckBoxelements - 1) ? 1 : 0 }]}>
<CheckBoxComponent
checkBoxKey={checkBoxKey}
itemKey={get(item , 'id')}
itemTitle={get(item , 'name', '')}
isCheckBoxSelected={get(item , 'isChecked' , '')}
onPressCheckBox={onPressChackBox}
checkBoxBackgroundColor={colors.DuckBlue}
options = {get(item, 'options')}
/>
</View>
)
})
}
如果我不通过 prop 选项,那么它可以正常工作,只有在有一些变化时才会呈现。
但是,如果我在 props 中传递 options 道具,那么即使没有变化,它也会每次都渲染。每次渲染都会使性能变慢。有什么方法可以解决它或为什么会这样。
【问题讨论】:
-
这个问题和你的previous one有什么区别?
标签: reactjs react-native react-redux react-router