Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
A library to determine if a variable or a statement is a React element or component. This article article describing elements and components and this article for an understanding of JSX syntax.
yarn add is-react
or npm i --save is-react
to use the package.
// Class Component
class Foo extends React.Component {
render(){
return <h1>Hello</h1>;
}
}
const foo = <Foo />;
//Functional Component
function Bar (props) { return <h1>World</h1> }
const bar = <Bar />;
// React Element
const header = <h1>Title</h1>;
// Check
isReact.compatible(Foo) // true
isReact.component(Foo); // true
isReact.classComponent(Foo); // true
isReact.functionComponent(Foo); // false
isReact.element(Foo); // false
isReact.compatible(<Foo />) // true
isReact.component(<Foo />) // false
isReact.element(<Foo />) // true
isReact.DOMTypeElement(<Foo />) // false
isReact.compositeTypeElement(<Foo />) // true
isReact.compatible(Bar) // true
isReact.component(Bar); // true
isReact.classComponent(Bar); // false
isReact.functionComponent(Bar); // true
isReact.element(Bar); // false
isReact.compatible(<Bar />) // true
isReact.component(<Bar />) // false
isReact.element(<Bar />) // true
isReact.DOMTypeElement(<Bar />) // false
isReact.compositeTypeElement(<Bar />) // true
isReact.compatible(header) // true
isReact.component(header); // false
isReact.element(header); // true
isReact.DOMTypeElement(header) // true
isReact.compositeTypeElement(header) // false
import isReact from 'is-react'
to use the package
All functions return a boolean
. The primary functions you will most likely
use are compatible()
, element()
, and component()
.
isReact.compatible()
Determine if a variable or statement is compatible with React. Valid React
components and elements return true
.
isReact.element()
Determine if a variable or statement is a React element. Will return true
for both DOM type and Composite type components.
isReact.component()
Determine if a variable or statement is a React component. Will return true
for both functional and class components.
isReact.classComponent()
Determine if a variable or statement is a React class component.
isReact.functionComponent()
Determine if a variable or statement is a React functional component.
isReact.DOMTypeElement()
Determine if a variable or statement is a React DOM type element.
isReact.compositeTypeElement()
Determine if a variable or statement is a React Composite type element.
Inspired by this Stackoverflow answer
FAQs
Determine if a variable or expression is a React element or component
The npm package is-react receives a total of 9,970 weekly downloads. As such, is-react popularity was classified as popular.
We found that is-react 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.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.