首页 > 其他分享 >[React Typescript] ComponentProps

[React Typescript] ComponentProps

时间:2023-05-07 16:11:14浏览次数:43  
标签:Typescript Get React props type ComponentProps

Blog: https://www.totaltypescript.com/react-component-props-type-helper

 

Get any Prop type from html element:

import { ComponentProps } from "react";

type ButtonProps = ComponentProps<"button">;

 

Get props type from a Component

const SubmitButton = (props: { onClick: () => void }) => {
  return <button onClick={props.onClick}>Submit</button>;
};

type SubmitButtonProps = ComponentProps<
  typeof SubmitButton
>;

 

With Ref:

Refs in React let you access and interact with the properties of an element. Often, it's used with form elements like inputs and buttons to extract their values or set their properties. The ComponentPropsWithRef does exactly what it says - provide the component props with its associated ref.

type InputProps = ComponentPropsWithRef<"input">;

标签:Typescript,Get,React,props,type,ComponentProps
From: https://www.cnblogs.com/Answer1215/p/17379465.html

相关文章

  • Reactor接口之四
    interval@TestpublicvoidtestInterval(){CountDownLatchcountDownLatch=newCountDownLatch(1);Flux.range(1,10).zipWith(Flux.interval(Duration.ofSeconds(1))).subscribe(System.out::println,null,countDownLatch::countD......
  • Reactor接口之三
    defer@TestpublicvoidtestDefer(){Flux.defer(()->{returnFlux.range(0,10);}).subscribe(System.out::println);}输出0到9。defer每次对结果Flux进行订阅时,懒惰地提供发布服务。因此实际的源实例化会推迟到每次订阅时。collect@Te......
  • 与chatGPT讨论c#的calss 与TypeScript中的calss问题
    与chatGPT讨论c#的calss与TypeScript中的calss问题目前来说chatGPT可以说是一场革命,它为我们提供了另一种选项,当你遇到问题的时候,只能去百度但度出来的结果大多不是我们想要的结果,特别是百度当你想要问度娘时......等到的却是一大堆广告,心中不由升起无明之火,不知百度能不能也搞......
  • Reactor接口之二
    merge@TestpublicvoidtestMerge(){Flux.merge(Flux.just(1,2,3),Flux.range(5,6)).subscribe(System.out::println);}merge将多个Flux合并成一个Flux。 @TestpublicvoidtestMerge1(){Flux.range(1,5).mergeWith(Flux.just(8,9......
  • typescript
    什么是typescripttypescript是微软开发的编程语言,它的后缀名是ts,通过编译可以将ts文件编译成ts文件,它定义了一些新语法使得开发起来可维护性更高也更好用,ts与js的区别如下图所示:在进行angular开发时,开发者不需要引入ts依赖,angular已经导入了ts依赖。快速上手ts编译tschell......
  • react-navigation 页面跳转
    使用react-navigation在进行页面跳转的时候,遇到些问题,现在来总结下,主要是web和android的差异react-navigation页面跳转方法navigationnavigate-转到另一个屏幕,找出需要采取的操作replace-用新屏幕替换当前屏幕push-将新屏幕推到堆栈上pop-回到堆栈中popToTo......
  • typescript重写canvas --10.绘制文字2
    typescript重写canvas--10.绘制文字21.使用canvas绘制文字<!DOCTYPEHTML><html><head><metacharset="utf-8"/></head><body><canvasid="myCanvas"width="450"height="400">你的浏览器......
  • React Native之JSX语法
    一、什么是JSXJSX即JavaScriptXML。一种在React组件内部构建标签的类XML语法。JSX为react.js开发的一套语法糖,也是react.js的使用基础。React在不使用JSX的情况下一样可以工作,然而使用JSX可以提高组件的可读性,因此推荐使用JSX。二、JSX的基本使用 2.1为什么使用JSX​原......
  • umi +react 搭建项目细节记录
    配置请求域名,有umirc.ts文件可以直接在该文件加proxy:{  '/api':{ //检测域名后面带/api/的路径   target:'http://192.168.0.90', //要请求的域名或IP地址   'changeOrigin':true,   //'pathRewrite':{'^/api':''......
  • kysely typescript 类型安全的sql 查询构建包
    typescript目前已经有不少方便的sql工具了,kysely是一个类型安全方便的sql查询构建工具对于使用typescript开发node服务的是个一个不错的选择,值得试用参考资料https://github.com/kysely-org/kyselyhttps://typeorm.io/https://github.com/typeorm......