JSPM

zod-prop-types

0.0.1-0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 29
  • Score
    100M100P100Q50245F
  • License MIT

A utility for transforming Zod schemas into PropTypes for React components

Package Exports

  • zod-prop-types

Readme

zod-prop-types

A utility for transforming Zod schemas into PropTypes for React components, ensuring type safety at runtime in a user-friendly and developer-friendly way.

npm version Build Status Coverage Status

Installation

npm install zod-prop-types
# or with yarn
yarn add zod-prop-types
# or with pnpm
pnpm add zod-prop-types

Usage

import { zodPropTypes } from "zod-prop-types";
import { z } from "zod";

// Define your Zod schema
const GreetingPropsSchema = z.object({ name: z.string(), age: z.number() });

// Create your component
const Greeting = ({ name, age }: z.infer<typeof GreetingPropsSchema>) => (
  <div>{`Hello, ${name}. You are ${age} years old.`}</div>
);

// Assign transformed Zod schema as propTypes
Greeting.propTypes = zodPropTypes(GreetingPropsSchema);

export { Greeting };

API Reference

zodPropTypes(ZodSchema)

  • ZodSchema: A Zod schema object.
  • Returns: An object of PropTypes validators for the given Zod schema.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details on how to contribute.

License

MIT © Patrick Eriksson