react-forwardref

React forwardRef does not seem to work with bootstrap Overlay

喜夏-厌秋 提交于 2021-01-28 05:11:15
问题 According to React-Bootstrap Overlays docs, the target of the overlay should be the element the overlay is positioned in relation to which works beautifully if the target is inline. such as the Example 1 below. If however the referenced dom item is contained inside of another component as illustrated with Example 2 then the reference is not setup correctly and the popover does not get positioned correctly. I was not forwarding the ref at first, and believed that to be my problem, but even

React/Typescript forwardRef types for an element which returns either an input or textArea

三世轮回 提交于 2021-01-27 04:12:19
问题 I'm trying to create a generic text input component for our application using react and typescript. I want it to be able to either be an input element or a textarea element based on a given prop. So it looks somewhat like this: import {TextArea, Input} from 'ourComponentLibrary' export const Component = forwardRef((props, ref) => { const Element = props.type === 'textArea' ? TextArea : Input return ( <Element ref={ref} /> ) }) This code works fine. However, when trying to incorporate types it