Javascript 函数组件的DOM引用?

Javascript 函数组件的DOM引用?,javascript,react-dom,react-forwardref,Javascript,React Dom,React Forwardref,我不确定如何为功能组件实现REF。我知道您需要使用forwardRef,但我不知道如何在代码的其他地方指向它们。例如,我正在渲染) 我想用reactstrap组件替换img: componentDidUpdate(prevProps, prevState) { if (this.props.activeMarker !== prevProps.activeMarker) { let img_ref = this.refs.image if (this.pro

我不确定如何为功能组件实现REF。我知道您需要使用forwardRef,但我不知道如何在代码的其他地方指向它们。例如,我正在渲染
我想用reactstrap组件替换img:

  componentDidUpdate(prevProps, prevState) {
    if (this.props.activeMarker !== prevProps.activeMarker) {
      let img_ref = this.refs.image
      if (this.props.showingInfoWindow) {
        img_ref.style.border = "2px solid black"
      }
      else {
        img_ref.style.border = null
      }
    }
  }

  return ( <img src={this.props.image} alt="unit" ref="cg_image" style={{width:200, height:100}} />)
const fancyCard=React.forwardRef((道具,ref)=>(
))
在componentDidMount中引用非字符串引用值的类似方式是什么

const fancyCard = React.forwardRef((props,ref) => (
   <CardImg ref={ref} top width="100%" src={this.props.image}/>
))