简体   繁体   English

React:当只有子组件需要重新渲染时,如何防止父组件重新渲染 onmousemove 状态更改?

[英]React: How can I prevent the parent component re-rendering onmousemove state change when only the child component needs re-rendering?

A parent component updates x,y properties in state onmousemove, these are then passed via props to a child component.父组件更新状态 onmousemove 中的 x,y 属性,然后这些属性通过 props 传递给子组件。 Currently both the parent and the chid re-renders onmousemove;目前,父节点和子节点都重新渲染 onmousemove; is there a way to prevent the re-render on the parent so that only the child re-renders?有没有办法防止在父级上重新渲染,以便只有子级重新渲染? Example: The parent is the bounding area, the child is a custom cursor.示例:父级为边界区域,子级为自定义光标。

保持子组件本地的 state(x,y coords)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM