
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@exah/react-base-component
Advanced tools
> Base component that prevents rendering unknown props in DOM
Base component that prevents rendering unknown props in DOM
react-html-attributes
(50% smaller - 3kb when minified / 1kb gziped, without many svg attributes and event handlers)as
prop$ yarn add @exah/react-base-component
Base
componentimport Base from '@exah/react-base-component'
as: Component
— React component or DOM element (like div
, input
, span
, ...), default div
asTagName: string
- DOM element used when React component passed to as
propSee createBase
for more options.
import { render } from 'react-dom'
import styled from 'react-emotion'
import Base from '@exah/react-base-component'
const LinkComp = styled(Base)`
color: ${props => props.foo === 'bar' ? 'royalblue' : 'hotpink'};
`
render((
<LinkComp as='a' href='http://example.com' foo='bar' abc='xyz'>
Click Me
</LinkComp>
), document.body)
// →
// <a class="css-0" href="http://example.com">Click Me</a>
createBase
factoryimport { createBase } from '@exah/react-base-component'
defaultComp: Component
— React component or DOM element (like div
, input
, span
, ...), default div
options: Object
— Options, optional, default to { componentProp: 'as' }
options.whitelist: Array
— List of props that always will be rendered, optionaloptions.blacklist: Array
— List of props that always be be omitted, optionaloptions.isPropValid: function (tagName, propName) => boolean
— Custom function to filter propsoptions.tagName: string
— DOM element. Used when defaultComp
is not DOM element, optionaloptions.componentProp: string
— Name of prop for changing underlying component, optional, default to 'as'
Return: Component
— wrapped in React.forwardRef
.
import { render } from 'react-dom'
import styled from 'react-emotion'
import { Link as RouterLink } from 'react-router-dom'
import { createBase } from '@exah/react-base-component'
const LinkComp = styled(createBase('span'))`
color: ${props => props.foo === 'bar' ? 'royalblue' : 'hotpink'};
`
const RouterLinkBase = createBase(RouterLink, {
tagName: 'a',
whitelist: [ 'to' ]
})
const CustomComp = createBase((props) => <span {...props} />, {
isPropValid: (tag, prop) => prop !== 'foo'
})
render((
<span>
<LinkComp as={RouterLinkBase} to='/page-2' foo='bar'>
Page 2
</LinkComp>
<LinkComp as='a' href='https://google.com' target='_blank' foo='baz'>
Search
</LinkComp>
<CustomComp title='notice' foo='bar'>
Notice
</CustomComp
</span>
), document.body)
// →
// <span>
// <a class="css-0" href="/app/page-2">Page 2</a>
// <a class="css-1" href="https://google.com" target="_blank">Search</a>
// <span class="css-1" title="notice">Notice</span>
// </span>
isPropValid
functionimport { isPropValid } from '@exah/react-base-component'
tagName: string
— DOM element (like a
, input
, div
)propName: string
— prop name (like href
, value
, onChange
)Return: boolean
import { isPropValid } from '@exah/react-base-component'
isPropValid('a', 'foo') // → false
isPropValid('a', 'bar') // → false
isPropValid('a', 'href') // → true
pss
— Prop Styles Systempss-components
— Components@emotion/is-prop-valid
— Inspired byMIT © John Grishin
FAQs
> Base component that prevents rendering unknown props in DOM
We found that @exah/react-base-component demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.