简体   繁体   English

当两个子组件相同且父组件在条件上不同时如何反应渲染

[英]How react render when both child components are same and parent component differs on condition

I am wondering about How react will render the component when on of the child component are same across different parent?我想知道当子组件在不同父组件上相同时,反应将如何呈现组件?

Lets says让我们说

render(){
  someFlag ? <div><MyComponent {...someprops} /></div> : <span><MyComponent {...someprops} /></span>
}

What i think is react many take a reference of MyComponent and serve the same reference with different props as it would be more efficient rather that creating new instance of the component, please guide me how react will render those changes should it create new instance as the parent component is different or my thinking is correct?, still i am relatively new to react我认为反应很多人引用 MyComponent 并使用不同的道具提供相同的引用,因为它会更有效而不是创建组件的新实例,请指导我如果反应创建新实例作为父组件不同或我的想法是正确的?,我还是比较新的反应

This will lead to a performance issue.这将导致性能问题。 As the parent element has changed from div to span on condition change or vice-versa, React will reconstruct the underlying component ie MyComponent .由于父元素在条件更改时从div更改为span ,反之亦然,React 将重建底层组件,即MyComponent

You can read more here .你可以在这里阅读更多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React - 当父状态组件发生更改时,如何强制子组件重新呈现? - React - How do i force child components to re render when parent state component changes? React.js父组件无法正确呈现子组件 - React.js parent component do not render child components correctly React:如何从父组件重新加载数据并在子组件更新时呈现? - React: How to reload data from parent component and render when child component do update? 当父组件的状态发生变化时,如何更新(重新渲染)React 中的子组件? - How to update (re-render) the child components in React when the parent's state change? React 在重新渲染父组件时如何重用子组件/保留子组件的 state? - How does React re-use child components / keep the state of child components when re-rendering the parent component? React:如何动态地将不同类型的子组件附加到父组件中? - React: How to dynamically append child components of differing types into a parent component? 如何让父组件在React中管理子组件的状态? - How to let a parent component manage the state of child components in React? 如何在 React 中渲染和更新来自父组件的子元素? - How to render and update child elements coming from a parent component in React? 延迟父组件渲染,直到所有子组件渲染reactjs - Delay parent component render till all the child components render reactjs 反应父组件检查子组件是否会呈现 - React parent component check if child will render
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM