| | |

Zod 27 🛡️ Runtime Prop Validation — zod-props for JavaScript Projects and Remotion Schemas

⏱️ Estimated read: 10 min | |

A React component receives whatever props its parent passes. In a JavaScript project, there is no compiler to check the shape, and in a TypeScript project, the compiler checks the call site but not the runtime value that arrives from an API, a JSON file, or a CMS. Runtime prop validation closes that gap: the component declares a Zod schema, the schema parses the props before the component renders, and a mismatch produces an error instead of a silently broken UI.

This chapter covers the two runtime prop validation patterns that matter in 2026. The zod-props package is a higher-order component that wraps a React component with a schema, designed for plain JavaScript projects that do not use TypeScript . Remotion’s schema integration is a different pattern: the schema is attached to a <Composition>, and Remotion uses it to validate input props, generate the visual editing controls, and (in v5) fail the render when the props are invalid . The sections that follow walk through the zod-props wrapper, the Remotion schema attachment, and the maintenance caveats that determine whether either is the right choice.

Key point: zod-props is a simple HOC that validates props at render time for JavaScript React projects, but it has been inactive since June 2024; Remotion’s schema integration is actively maintained and validates props during rendering, with the schema also driving the Studio’s visual controls.


a. zod-props and the higher-order component pattern

zod-props exports a default function called zop that takes a React component and a Zod schema and returns a wrapped component. The wrapper parses the incoming props against the schema on every render, and if the parse fails, it throws the ZodError . The pattern is the same as a higher-order component that enforces a contract: the original component stays unchanged, and the exported component is the validated version.

import zop from 'zod-props';
import { z } from 'zod';

const Props = z.object({
  name: z.string(),
  age: z.number().optional(),
});

const MyComponent = ({ name, age }) => (
  <div>
    <h1>Hello, {name}!</h1>
    {age && <p>Age: {age}</p>}
  </div>
);

export default zop(MyComponent, Props);

The package’s stated target is JavaScript projects that do not use TypeScript. The README emphasizes “No TypeScript required for the consumer,” which is the exact use case: a .jsx codebase that wants runtime prop checks without adopting the TypeScript toolchain . In a TypeScript project, the schema’s inferred type can be used with z.infer, and the HOC is redundant with the compiler’s checks for the call site—but it still catches runtime values that the compiler cannot see, such as props from JSON.parse or a network response.

The maintenance caveat is significant. The package was last published in June 2024, has a single maintainer, and Snyk’s health analysis classifies it as “Inactive” with roughly 8 weekly downloads . No direct vulnerabilities have been reported , but an inactive package with a single maintainer is a risk for a production dependency. The HOC is small enough that the pattern can be implemented in the project itself—a withSchema function that calls Schema.parse(props) and returns the component—without the dependency.


b. Remotion schemas and the <Composition> integration

Remotion’s schema integration is a different mechanism with a broader scope. The schema is attached to a <Composition> via the schema prop, and Remotion uses it for three purposes: validating the input props during rendering, generating the visual controls in the Remotion Studio, and marking invalid props in the Studio editor .

// MyComponent.tsx
import { z } from 'zod';

export const myCompSchema = z.object({
  propOne: z.string(),
  propTwo: z.string(),
});

export const MyComponent = ({ propOne, propTwo }) => (
  <div>
    <h1>{propOne}</h1>
    <h2>{propTwo}</h2>
  </div>
);
// Root.tsx
import { Composition } from 'remotion';
import { MyComponent, myCompSchema } from './MyComponent';

export const RemotionRoot = () => (
  <Composition
    id="my-video"
    component={MyComponent}
    durationInFrames={100}
    fps={30}
    width={1920}
    height={1080}
    schema={myCompSchema}
    defaultProps={{
      propOne: 'Hello World',
      propTwo: 'Welcome to Remotion',
    }}
  />
);

The schema must be a z.object() at the top level, because the props of a React component are always an object . Remotion merges the input props with the defaultProps shallowly, then validates the merged object against the schema. In Remotion 4.0, invalid props produce a warning listing each invalid field, and the render proceeds anyway; in Remotion 5.0, the render fails with an error . The @remotion/zod-types package adds Remotion-specific types like zColor(), zTextarea(), and zMatrix() that generate specialized controls in the Studio .

The schema is optional. Remotion infers basic controls from defaultProps since v4.0.516, and the schema is only needed when the props require validation, constraints, choices, descriptions, or specialized controls . This is the same principle as the zod-props case: the schema is for the cases where the runtime value matters, not for every component.


c. Choosing between the patterns and the maintenance risk

The two patterns serve different scopes. zod-props is a general React HOC for any component in a JavaScript project. Remotion’s schema is specific to video compositions: it validates the props passed to a render and drives the Studio’s editing UI. A project that uses Remotion does not need zod-props for its compositions—the schema prop is the built-in mechanism. A JavaScript React project that does not use Remotion and wants prop validation has zod-props as an option, but the package’s inactivity suggests that a hand-written HOC is the safer choice.

The hand-written version is four lines. It takes a component and a schema, returns a function that parses the props and either renders the component with the parsed data or throws. The parsed data is the schema’s output, which means the component receives the coerced and defaulted values, not the raw props.

import { z } from 'zod';

function withSchema(Component, schema) {
  return function Validated(props) {
    const parsed = schema.parse(props); // throws on mismatch
    return <Component {...parsed} />;
  };
}

The trade-off is that the hand-written version does not get the package’s error formatting or any future fixes. But the package has not had a release since 2024, so “future fixes” is theoretical. For a JavaScript project that wants the HOC pattern, the four-line version is the lower-risk dependency.


Complete Example Session

// ============================================
// PART 1: THE zod-props HOC
// ============================================
// npm install zod-props zod
import zop from 'zod-props';
import { z } from 'zod';

const ButtonProps = z.object({
  label: z.string(),
  variant: z.enum(['primary', 'secondary']).default('primary'),
  onClick: z.function(),
});

const Button = ({ label, variant, onClick }) => (
  <button className={variant} onClick={onClick}>{label}</button>
);

// Export the validated component
export default zop(Button, ButtonProps);

// ============================================
// PART 2: THE HAND-WRITTEN EQUIVALENT
// ============================================
function withSchema(Component, schema) {
  return function Validated(props) {
    const parsed = schema.parse(props);
    return <Component {...parsed} />;
  };
}

export default withSchema(Button, ButtonProps);

// ============================================
// PART 3: THE REMOTION SCHEMA
// ============================================
// npm install zod
import { z } from 'zod';

export const videoSchema = z.object({
  title: z.string(),
  subtitle: z.string().optional(),
});

// In Root.tsx:
// <Composition schema={videoSchema} defaultProps={{ title: 'Hi' }} ... />

The parts covered the zod-props HOC, the hand-written equivalent, and the Remotion schema attachment.


Quick Reference

zod-props

ItemDetail
Importimport zop from 'zod-props'
Usagezop(Component, Schema)
BehaviorParses props on every render, throws on mismatch
TargetJavaScript React projects
Last releaseJune 2024
MaintenanceInactive

Remotion Schemas

ItemDetail
Attachmentschema prop on <Composition>
Top-level typeMust be z.object()
ValidationDuring rendering, after merging with defaultProps
Studio controlsGenerated from the schema
v4 behaviorWarning, render proceeds
v5 behaviorRender fails
Remotion types@remotion/zod-types (zColor, zTextarea, etc.)

The Hand-Written HOC

function withSchema(Component, schema) {
  return (props) => <Component {...schema.parse(props)} />;
}

Best Practices

✅ Do This:

// Use the HOC pattern for runtime validation in JS projects
export default zop(MyComponent, Props);                       // ✅

// Use the schema prop for Remotion compositions
<Composition schema={mySchema} defaultProps={...} />          // ✅

// Hand-write the HOC if the dependency risk is unacceptable
function withSchema(C, S) { return (p) => <C {...S.parse(p)} />; } // ✅

❌ Don’t Do This:

// Use zod-props in a TypeScript project where the compiler already checks
// (redundant unless runtime values are untrusted)              // ❌

// Skip the schema for Remotion when props need validation
// (the schema is optional, but validation is the reason to add it) // ❌

// Assume the package is actively maintained
// (last release June 2024)                                     // ❌

Common Pitfalls

PitfallWhy It HappensFix
Prop error at renderSchema does not match propsFix the schema or the caller
Remotion render fails in v5Invalid props against schemaFix the input props
Dependency riskzod-props inactiveHand-write the HOC
Remotion schema not driving controlsTop-level type not z.object()Wrap in z.object()

Real-World Examples

1. zod-props HOC

export default zop(MyComponent, Props);

2. Hand-written HOC

const Validated = withSchema(MyComponent, Props);

3. Remotion schema

export const schema = z.object({ title: z.string() });

4. Remotion attachment

<Composition schema={schema} defaultProps={{ title: 'Hi' }} />

5. Remotion type

type Props = z.infer<typeof schema>;

6. Optional prop in schema

subtitle: z.string().optional()

7. Enum prop

variant: z.enum(['primary', 'secondary'])

8. Remotion Studio control

// zColor() generates a color picker

9. Parse on render

const parsed = schema.parse(props);

10. v5 render failure

Invalid props → render fails with error

Visual

The HOC Flow

┌─────────────────────────────────────────────────────────┐
│  Parent passes props                                    │
│         │                                               │
│         ▼                                               │
│  zop(Component, Schema)                                 │
│         │                                               │
│         ▼                                               │
│  Schema.parse(props)                                    │
│         │                                               │
│    ┌────┴────┐                                          │
│    ▼         ▼                                          │
│  valid     invalid                                      │
│    │         │                                          │
│    ▼         ▼                                          │
│  render    throw ZodError                               │
│  Component                                              │
└─────────────────────────────────────────────────────────┘

Remotion Schema Flow

┌─────────────────────────────────────────────────────────┐
│  <Composition schema={s} defaultProps={d} />           │
│         │                                               │
│         ▼                                               │
│  Input props merged with defaults (shallow)             │
│         │                                               │
│         ▼                                               │
│  Schema validates merged props                          │
│         │                                               │
│    ┌────┴────┐                                          │
│    ▼         ▼                                          │
│  valid     invalid                                      │
│    │         │                                          │
│    ▼         ▼                                          │
│  render    v4: warn, render                             │
│            v5: fail                                     │
└─────────────────────────────────────────────────────────┘

Package Health

┌─────────────────────────────────────────────────────────┐
│  zod-props                                              │
│  Last release: June 2024                                │
│  Weekly downloads: ~8                                    │
│  Maintainers: 1                                          │
│  Status: Inactive                                        │
│                                                         │
│  The HOC is small; hand-write it if the risk matters.   │
└─────────────────────────────────────────────────────────┘

Summary

ItemValue
General React HOCzod-props (zop(Component, Schema))
HOC behaviorParses props, throws on mismatch
HOC maintenanceInactive since June 2024
Remotion schemaschema prop on <Composition>
Remotion top-level typeMust be z.object()
Remotion validationDuring rendering, after merging with defaults
Remotion v5 behaviorRender fails on invalid props

Key takeaways:

  • zod-props is a simple HOC for JavaScript React projects. It wraps a component with a schema and parses the props on every render, throwing a ZodError on mismatch. It is designed for projects that do not use TypeScript .
  • The package is inactive. The last release was June 2024, the maintainer count is one, and the download volume is negligible. The HOC is small enough that a hand-written version is the lower-risk choice for a production dependency .
  • Remotion’s schema integration is a different pattern. The schema is attached to a <Composition>, and Remotion uses it to validate input props, generate the Studio controls, and (in v5) fail the render on invalid props .
  • Remotion requires a top-level z.object(). The props of a React component are an object, and Remotion’s schema integration assumes that shape. The @remotion/zod-types package adds Remotion-specific controls .
  • Both patterns are for runtime values the compiler cannot see. A TypeScript project checks the call site but not the JSON that arrives from an API or a CMS. The schema is the runtime check for those values.

Remember: Runtime prop validation is for the values that arrive after the compiler has finished. zod-props is a small HOC that parses props on render, but the package is inactive and the same pattern can be hand-written in four lines. Remotion’s schema integration is the built-in mechanism for video compositions, and it does more than validate: it drives the Studio’s editing controls. Use the schema where the runtime value matters, and treat the dependency as a decision about maintenance risk, not just functionality.

Was this helpful?


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!