clone-element

pass ref to a class component with React.cloneElement and render prop

余生颓废 提交于 2019-12-07 07:37:12
问题 I'm writing a component that handle some internal state according to a ref of it's child (a mouse event related to that child's ref for example). This component is using a render-prop to pass on the relevant piece of state to it's child, and render the child with the ref attached via React.cloneElement util. The problem is that when the child is a class component, for some reason the ref is not available, and i can't find a way to render it as it's a react element object with a type of

pass ref to a class component with React.cloneElement and render prop

試著忘記壹切 提交于 2019-12-05 11:33:16
I'm writing a component that handle some internal state according to a ref of it's child (a mouse event related to that child's ref for example). This component is using a render-prop to pass on the relevant piece of state to it's child, and render the child with the ref attached via React.cloneElement util. The problem is that when the child is a class component, for some reason the ref is not available, and i can't find a way to render it as it's a react element object with a type of function (after i clone it of course). But if the child is just a DOM node like a div for example, it is