
Security News
Official Go SDK for MCP in Development, Stable Release Expected in August
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
react-html-props
Advanced tools
This package includes convenience TypeScript type definitions for all React.DetailedHTMLProps
for all HTML element types.
For example, this allows you to specify DivProps
instead of React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
. Because nobody wants to type all of that. đ
Using these types makes it easy to support all standard HTML props for your components.
DivProps
.npm i react-html-props
Let's use div
as an example since it's the most common.
You can use DivProps
to support all props for div
in your own components.
import { DivProps } from "react-html-props";
export const MyComponent = ({ children, ...divProps }: DivProps): JSX.Element => {
return <div {...divProps}>{children}</div>;
};
Here we are using object destructuring to unpack children
from the rest of div
's props.
You will likely have your own props, of course.
So you can use TypeScript's intersection types notation to combine your own props with the HTML element's props.
Then use object destructuring to unpack your own props out of the resulting combined type.
Just follow the example below:
import { DivProps } from 'react-html-props';
interface PandaBearComponentProps {
pandaBearCount: 10;
}
export const PandaBearComponent = ({
children,
pandaBearCount,
...divProps
}: PandaBearComponentProps & DivProps): JSX.Element => {
return (
<div {...divProps}>
<h1>I have {pandaBearCount} panda bears</h1>
<div>{children}</div>
</div>
);
};
The goal was to make it as easy to use each HTML element's props as possible, so the types for all props begin with the exact HTML element.
For example, the type for the p
element's props is PProps
.
In some cases there are multiple types available, such as with headings h1
, h2
, h3
, etc. The props for these elements can be referenced either as H1Props
, H2Props
, H3Props
, etc, or simply as HeadingProps
. See the table below for more.
You can import any of the following types:
HTML Element | Props Type To Use |
---|---|
anchor | AnchorProps |
area | AreaProps |
audio | AudioProps |
base | BaseProps |
body | BodyProps |
br | BRProps |
button | ButtonProps |
canvas | CanvasProps |
data | DataProps |
datalist | DataListProps |
dialog | DialogProps |
div | DivProps |
dl | DLProps |
embed | EmbedProps |
fieldset | FieldSetProps |
form | FormProps |
h1 | H1Props , HeadingProps |
h2 | H2Props , HeadingProps |
h3 | H3Props , HeadingProps |
h4 | H4Props , HeadingProps |
h5 | H5Props , HeadingProps |
h6 | H6Props , HeadingProps |
head | HeadProps |
hr | HRProps |
html | HtmlProps |
iframe | IFrameProps |
img | ImgProps |
input | InputProps |
ins | InsProps , ModProps |
del | DelProps , ModProps |
label | LabelProps |
legend | LegendProps |
li | LIProps |
link | LinkProps |
map | MapProps |
meta | MetaProps |
object | ObjectProps |
ol | OLProps |
optgroup | OptGroupProps |
option | OptionProps |
p | PProps , ParagraphProps |
param | ParamProps |
pre | PreProps |
progress | ProgressProps |
blockquote | BlockQuoteProps , QuoteProps |
q | QProps , QuoteProps |
cite | CiteProps , QuoteProps |
slot | SlotProps |
script | ScriptProps |
noscript | NoScriptProps , ScriptProps |
select | SelectProps |
source | SourceProps |
span | SpanProps |
style | StyleProps |
svg | SVGProps |
table | TableProps |
col | ColProps , TableColProps |
colgroup | ColGroupProps , TableColProps |
td | TDProps , TableDataCellProps |
th | THProps , TableHeaderCellProps |
tr | TRProps , TableRowProps |
thead | THeadProps , TableSectionProps |
tbody | TBodyProps , TableSectionProps |
tfoot | TFootProps , TableSectionProps |
template | TemplateProps |
textarea | TextAreaProps |
title | TitleProps |
track | TrackProps |
ul | ULProps |
video | VideoProps |
webview | WebViewProps |
This is a TypeScript project and only relevant to React projects written in TypeScript.
Open source software is awesome and so are you. đ
Feel free to submit a pull request for bugs or additions, and make sure to update tests as appropriate. If you find a mistake in the docs, send a PR! Even the smallest changes help.
For major changes, open an issue first to discuss what you'd like to change.
If you found this project helpful, let the community know by giving it a star: đâ
Copyright Š 2021 Justin Mahar https://github.com/justinmahar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
FAQs
Convenient TypeScript types for all React HTML props.
The npm package react-html-props receives a total of 44,061 weekly downloads. As such, react-html-props popularity was classified as popular.
We found that react-html-props demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.