
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
react-desc
Advanced tools
Add a schema to your React components based on React PropTypes
npm install react-desc
// Anchor.js
import React from 'react';
import ReactPropTypes from 'prop-types';
import { describe, PropTypes } from 'react-desc';
const Anchor = (props) => {
const { path, ...rest } = props;
return (
<a href={path} {...rest}>{props.children}</a>
);
};
export const AnchorWithSchema = describe(Anchor)
.availableAt([
{
badge: 'https://codesandbox.io/static/img/play-codesandbox.svg',
url: 'https://codesandbox.io/s/github/grommet/grommet-site?initialpath=anchor&module=%2Fscreens%2FAnchor.js',
},
])
.description('A text link');
AnchorWithSchema.propTypes = {
path: PropTypes.string.describe('React-router path to navigate to when clicked').isRequired,
href: PropTypes.string.describe('link location').deprecated('use path instead'),
id: ReactPropTypes.string, // this will be ignored for documentation purposes
title: PropTypes.custom(() => {}).description('title used for accessibility').format('XXX-XX'),
target: PropTypes.string.describe('target link location').defaultValue('_blank'),
};
export default Anchor;
JSON output
import { AnchorWithSchema } from './Anchor';
const documentation = AnchorWithSchema.toJSON();
Expected output:
{
"name": "Anchor",
"description": "A text link",
"properties": [
{
"description": "React-router path to navigate to when clicked",
"name": "path",
"required": true,
"format": "string"
},
{
"description": "link location.",
"name": "href",
"deprecated": "use path instead",
"format": "string"
},
{
"description": "title used for accessibility.",
"name": "title",
"format": "XXX-XX"
},
{
"description": "target link location.",
"name": "target",
"defaultValue": "_blank",
"format": "string"
}
]
}
Markdown output
import Anchor from './Anchor';
const documentation = Anchor.toMarkdown();
Expected output:
## Anchor Component
A text link
### Properties
| Property | Description | Format | Default Value | Required | Details |
| ---- | ---- | ---- | ---- | ---- | ---- |
| **path** | React-router path to navigate to when clicked | string | | Yes | |
| **~~href~~** | link location. | string | | No | **Deprecated**: use path instead |
| **title** | title used for accessibility. | XXX-XX | | No | |
| **target** | target link location. | string | _blank | No | |
Typescript output
Format entry will be a valid typescript definition.
import { AnchorWithSchema } from './Anchor';
const documentation = AnchorWithSchema.toTypescript();
Expected output:
{
"name": "Anchor",
"description": "A text link",
"properties": [
{
"description": "React-router path to navigate to when clicked",
"name": "path",
"required": true,
"format": "string"
},
{
"description": "link location.",
"name": "href",
"deprecated": "use path instead",
"format": "string"
},
{
"description": "title used for accessibility.",
"name": "title",
"format": "any"
},
{
"description": "target link location.",
"name": "target",
"defaultValue": "_blank",
"format": "string"
}
]
}
describe(component)
Creates a proxy to the actual react component with support for the following functions:
PropTypes
Proxy around the React propTypes, all properties are supported. See all options here. This proxy supports the following functions:
react-docgen is a great project but it relies on an AST parser to generate documentation. Most of the time this is ok, but for us the following use cases were hard to solve without a more verbose way to define propTypes:
Define deprecated properties
Define a required property for custom function:
Anchor.propTypes = {
test: () => { ... } // isRequired is not present here
}
Allow internal comments for properties without it showing up in the documentation
FAQs
Add an schema to your React components based on React PropTypes.
The npm package react-desc receives a total of 2,733 weekly downloads. As such, react-desc popularity was classified as popular.
We found that react-desc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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 Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.