【发布时间】:2020-09-24 16:16:37
【问题描述】:
我有一个像这样的纯组件?
interface Props {
checkBoxTitleStyle?: any
checkBoxBackgroundColor?: any
onPressCheckBox?: (id, isChecked, selectedArray , options?: CheckBoxOptions) => void
itemKey?: any
mainContainerStyle?: any
}
class CheckBoxComponent extends PureComponent<Props> {
constructor()
render()
}
现在当我在我的 otherComponent 中使用这个 pureComponents
<CheckBoxComponent
checkBoxKey={checkBoxKey}
itemKey={get(item , 'id')}
itemTitle={get(item , 'label', '')}
isCheckBoxSelected={get(item , 'isChecked' , '')}
checkBoxBackgroundColor={colors.DuckBlue}
/>
如果我不通过道具 mainContainerStyle 那么它工作正常,它只在有一些变化时呈现。
但是如果我在 props 中传递 mainContainerStyle,那么即使没有变化,它也会每次都渲染。每次渲染都会使性能变慢。有什么方法可以解决它或为什么会这样。
【问题讨论】:
-
你是如何传递 mainContainerStyle 的?我没有在代码中看到它
-
我添加了一个新问题。 stackoverflow.com/questions/62218097/…
标签: reactjs react-native react-redux react-router