@lynx-js/react / forwardRef

函数: forwardRef()

function forwardRef<T, P>(render: ForwardRefRenderFunction<T, PropsWithoutRef<P>>): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>

Lets your component expose a DOM node to a parent component using a ref.

类型参数

类型参数默认类型描述
T-The type of the DOM node.
PobjectThe props the component accepts, if any.

参数

范围类型描述
renderForwardRefRenderFunction<T, PropsWithoutRef<P>>See the ForwardRefRenderFunction.

返回

ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>

参阅

示例

interface Props {
  children?: ReactNode;
  type: "submit" | "button";
}

export const FancyButton = forwardRef<HTMLButtonElement, Props>((props, ref) => (
  <button ref={ref} className="MyClassName" type={props.type}>
    {props.children}
  </button>
));

定义于

.pnpm/@types+react@18.3.28/node_modules/@types/react/ts5.0/index.d.ts:1614

除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。