> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Editor React Component Extension Files and Code

## Article: Editor React Component Extension Files and Code

## Article Link: https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/supported-extensions/site/editor-react-components/editor-react-component-extension-files-and-code.md

## Article Content:

# Editor React Component Extension Files and Code

<blockquote class="caution">

**Editor Compatibility**

Editor React Component extensions are built for [Wix Harmony](https://dev.wix.com/docs/build-apps/get-started/overview/about-apps-in-wix-harmony-and-wix-studio-two.md), Wix's AI-powered editor. They're not supported on Wix Editor or Wix Studio sites, and there's no way to conditionally switch between extension types based on the editor.

</blockquote>

When you [add an Editor React Component extension](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/supported-extensions/site/editor-react-components/add-an-editor-react-component-extension-with-the-wix-cli.md) to your CLI project, the CLI generates a component folder with the name you choose, containing the following files:

## Which file does what

The folder holds 7 files. Most of your work happens in 3 of them, and 2 you never touch:

| File | You edit it? | What it's for |
|------|--------------|---------------|
| `<component-name>.tsx` | Yes | Your component's UI logic and JSX. This is where you spend most of your time. |
| `<component-name>.props.ts` | Yes | The component's props type and its `defaultProps`. |
| `<component-name>.module.css` | Yes | The component's styles, scoped as a CSS Module. |
| `<component-name>.extension.ts` | Yes | The component's identity, installation, and resources, plus any overrides you apply to the generated manifest. |
| `component.preview.tsx` | Only if needed | How the component renders in the editor, when that should differ from the live site. |
| `component.tsx` | No | The entry point that wires your component to its default props. |
| `<component-name>.generated.ts` | No | The auto-generated manifest. Overwritten every time you regenerate. |

The 3 files at the top of the list are the ones the manifest is derived from. When you run [`wix app generate manifest`](https://dev.wix.com/docs/wix-cli/cli-for-apps/command-reference/project-commands/generate-manifest.md), the CLI reads your JSX, your prop types, and your CSS rules, and writes `<component-name>.generated.ts` from them. You never edit that output directly. To change the manifest, either change the source files and regenerate, or override the result in `<component-name>.extension.ts`.

Keeping the props type and `defaultProps` together in `<component-name>.props.ts` matters, because both `<component-name>.tsx` and `component.tsx` import from it. One shared file avoids a circular dependency between your component and the files that wire it up.

<blockquote class="important">

**Important:** Before you start building, review the [manifest validation rules and unsupported features](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/about-the-manifest.md).

</blockquote>

## component-name.extension.ts

The `<component-name>.extension.ts` file defines your component's identity, installation behavior, and code resources. It also imports the auto-generated `editorElement` from `<component-name>.generated.ts` and combines it with the rest of the configuration. This file is required, so don't delete it after the component is generated. If you add your own files, you must include `<component-name>.extension.ts`.

You own this file and edit it manually. The CLI doesn't overwrite it when you regenerate the manifest.

When you generate a new Editor React Component in your project, `<component-name>.extension.ts` looks like this:

```typescript
import { extensions } from '@wix/custom-extensions';
import { LAYOUT } from '@wix/react-component-schema';
import { withEditorElementDefaults } from '@wix/react-component-utils';
import { deepmerge } from 'deepmerge-ts';
import { editorElement } from './my-component.generated';
import { defaultProps } from './my-component.props';
import componentUrl from './component.tsx?url';
import componentPreviewUrl from './component.preview.tsx?url';

const editorElementWithDefaults = withEditorElementDefaults(editorElement, defaultProps);

export default extensions.editorReactComponent({
  id: 'adbc7076-6062-4a96-9bf9-7760e803789c',
  type: 'myAppCodeIdentifier.MyComponent',
  displayName: 'My Component',
  description: 'A short description of what the component does',
  editorElement: deepmerge(editorElementWithDefaults, {
    layout: {
      resizeDirection: LAYOUT.RESIZE_DIRECTION.horizontalAndVertical,
      contentResizeDirection: LAYOUT.CONTENT_RESIZE_DIRECTION.vertical,
    },
  }),
  installation: {
    initialSize: {
      width: { sizingType: LAYOUT.SIZING_TYPE.pixels, pixels: 250 },
      height: { sizingType: LAYOUT.SIZING_TYPE.content },
    },
  },
  resources: {
    client: { componentUrl },
    editor: { componentUrl: componentPreviewUrl },
  },
});
```

The generated configuration includes:

| Key | Type | Description |
|-----|------|-------------|
| `id` | string | Unique identifier for your component. Don't change it after you release a version. |
| `type` | string | A unique reference for your component, made up of your app's [code identifier](https://dev.wix.com/docs/build-apps/develop-your-app/app-workspace/app-dashboard/code-identifier.md) followed by a name you choose for the component. Don't change it after you release a version. |
| `displayName` | string | The component's name. |
| `description` | string | Brief description of your component. |
| `editorElement` | object | The manifest section that declares which parts of your component Wix users can edit and how the [auto panels](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/auto-panels/about-auto-panels.md) are configured. Built from the auto-generated `editorElement`, with your overrides merged on top. |
| `installation` | object | Controls how the component is added to a page, including its initial size, optional placement, default presets, and fixed position. |
| `resources.client.componentUrl` | string | The component the live site loads. Imported from `component.tsx` with Vite's `?url` suffix, which resolves to the built asset's URL. |
| `resources.editor.componentUrl` | string | The component the editor loads. Imported from `component.preview.tsx` the same way. |
| `resources.translations` | object | Optional. Base path and languages for your component's translation JSON files. |

### Installation options

The `installation` object controls how your component appears when a Wix user first adds it to a page. It works together with `layout` in `editorElement`: `installation` sets the starting size and placement, and `layout` controls how the Wix user can resize from there.

```typescript
installation: {
  staticContainer: 'HOMEPAGE',
  presets: {
    default: 'desktopCard',
    small: 'mobileCard',
  },
  initialSize: {
    width: { sizingType: LAYOUT.SIZING_TYPE.pixels, pixels: 320 },
    height: { sizingType: LAYOUT.SIZING_TYPE.pixels, pixels: 240 },
  },
},
```

If you omit `small`, the desktop preset cascades to mobile. Setting `small`, or editing the component in the mobile view, breaks that cascade.

For the full set of `installation` properties, including `fixedPosition` for pinning a component to the page, and more examples, see [Installation](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/root-properties/installation.md).

### Translations

Component translations are JSON files you host with your component; the viewer loads the file that matches the site language at runtime. Declare them in `resources.translations`, and add the `viewer-core/translations` service dependency so your component can read the strings:

```typescript
resources: {
  client: {
    componentUrl,
    dependencies: {
      serviceDependencies: ['viewer-core/translations'],
    },
  },
  editor: { componentUrl: componentPreviewUrl },
  translations: {
    basePath: 'https://mycdn.com/my-component/translations/',
    languages: ['en', 'es', 'fr'],
  },
},
```

In `<component-name>.tsx`, look up keys with the translations service:

```tsx
import { useService } from '@wix/services-manager-react';
import { TranslationsDefinition } from '@wix/viewer-service-translations/definition';

const { translate } = useService(TranslationsDefinition);
const t = translate('myComponent');
```

For the translation file format, the full property reference, and more examples, see [Resources](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/resources.md).

### Overriding the generated manifest

Most of your `editorElement` comes from `<component-name>.generated.ts`, which you can't edit. `<component-name>.extension.ts` is where you change it, and the scaffold sets up 2 helpers to make that safe.

**`withEditorElementDefaults`** fills in the manifest's default values from your component's `defaultProps`:

```typescript
const editorElementWithDefaults = withEditorElementDefaults(editorElement, defaultProps);
```

This is why the editor panels open showing the same values your component renders, and why you set your defaults once in `<component-name>.props.ts` instead of writing `defaultValue` into every data item.

**`deepmerge`**, from [deepmerge-ts](https://www.npmjs.com/package/deepmerge-ts), layers your own settings on top:

```typescript
editorElement: deepmerge(editorElementWithDefaults, {
  layout: {
    resizeDirection: LAYOUT.RESIZE_DIRECTION.horizontalAndVertical,
  },
}),
```

Use `deepmerge` rather than assigning `editorElement` directly, so that adding a `layout` block doesn't discard the generated `data`, `elements`, and `cssProperties` underneath it.

Override only what the generator can't work out on its own, such as `layout` and `installation`. Anything derived from your component's code, CSS, or prop types belongs in the source files instead, so your change survives the next regeneration.

For comprehensive documentation on configuring your manifest, see [About the Manifest](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/about-the-manifest.md) and the [Manifest Walkthrough](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/auto-panels/tutorial-configure-auto-panels.md).

## component-name.generated.ts

The `<component-name>.generated.ts` file holds the auto-generated [`editorElement`](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/editor-element/editor-element.md) portion of your manifest. The CLI produces this file by reading your React component's JSX, CSS, and prop types.

As you iterate on your component, keeping the manifest in sync depends on how you work:

- **Manual edits**: The manifest doesn't stay in sync automatically while you edit files yourself. Regenerate it by running [`wix app generate manifest`](https://dev.wix.com/docs/wix-cli/cli-for-apps/command-reference/project-commands/generate-manifest.md).
- **AI edits with the Wix skill**: Manifest regeneration happens as part of the Editor React Component [Wix skill](https://dev.wix.com/docs/api-reference/articles/ai-tools/about-wix-skills.md) workflow.
- **Writing the manifest yourself**: Using the generated manifest is optional. You can stop importing `editorElement` from `<component-name>.generated.ts` in `<component-name>.extension.ts`, and instead define `editorElement` there directly, or move it to a file of your own. Once you do this, nothing keeps it in sync with your component automatically: keeping it accurate as your component changes becomes your responsibility.

<blockquote class="important">

**Important:** Keep `<component-name>.generated.ts` in place and wired up if you want the Editor React Component [Wix skill](https://dev.wix.com/docs/api-reference/articles/ai-tools/about-wix-skills.md) to author or update your component with AI. The skill relies on this file to work.

</blockquote>

[`editorElement`](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/editor-element/editor-element.md) is the largest part of the manifest. It declares the data your component exposes, the inner elements that Wix users can select, the CSS properties they can customize, and any presets, states, or layout behavior. The editor reads these declarations to build the matching [auto panels](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/auto-panels/about-auto-panels.md).

A generated file looks like this:

```typescript
import type { EditorElement } from '@wix/react-component-schema';

export const editorElement = {
  selector: '.my-editor-react',
  displayName: 'My Editor React',
  data: {
    label: { dataType: 'text', displayName: 'Label' },
    step: { dataType: 'number', displayName: 'Step' },
  },
  // ...elements, cssProperties, presets, states, layout
} as EditorElement;
```

<blockquote class="caution">

**Caution**: Don't edit `<component-name>.generated.ts` directly. Manual changes are overwritten the next time the manifest regenerates. To regenerate this file after manual changes to your component, run [`wix app generate manifest`](https://dev.wix.com/docs/wix-cli/cli-for-apps/command-reference/project-commands/generate-manifest.md).

</blockquote>

## component-name.tsx

The `<component-name>.tsx` file is where you write the React code that defines your component. You can write code in other files and include it here, but you must return your main component in this file. This is where the CLI will look for the component definition.

The CLI reads this file when regenerating `<component-name>.generated.ts`, so the structure of your JSX, CSS classes, and prop types directly shape the auto-generated `editorElement`. After you edit this file manually, run [`wix app generate manifest`](https://dev.wix.com/docs/wix-cli/cli-for-apps/command-reference/project-commands/generate-manifest.md) to keep the generated manifest in sync.

This file is required for the component to work, so don't delete it. If you add the files on your own, you must include `<component-name>.tsx`.

When the `<component-name>.tsx` file is generated, it looks like this:

```tsx
import type { FC } from 'react';
import classNames from 'classnames';
import styles from './my-component.module.css';
import type { MyComponentProps } from './my-component.props';

const MyComponent: FC<MyComponentProps> = ({
  id,
  className,
  image,
  title,
  description,
  direction,
}) => {
  return (
    <div
      id={id}
      dir={direction}
      className={classNames('my-component', styles.myComponent, styles.fallbackDirection, className)}
    >
      {image?.url ? (
        <img className={classNames('image', styles.image)} src={image.url} alt={image.alt} />
      ) : (
        <div className={classNames('image', styles.imagePlaceholder)} aria-hidden="true" />
      )}
      <div className={styles.body}>
        <h2 className={classNames('title', styles.title)}>{title}</h2>
        <p className={classNames('description', styles.description)}>{description}</p>
      </div>
    </div>
  );
};

export default MyComponent;
```

The file defines a React functional component that imports its props type from `<component-name>.props.ts`. The props map directly to the `data` keys in the manifest's `editorElement`, which is auto-generated from this file, plus `id` and `className`, which Wix always provides. For more details, see [Runtime Props](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/runtime-props.md).

### How class names shape the manifest

The generated code composes class names in a specific way, and your own components need to follow the same pattern. Look at the root element:

```tsx
className={classNames('my-component', styles.myComponent, styles.fallbackDirection, className)}
```

Each entry does a different job:

- `'my-component'`: A plain string class, sometimes called a global class. This is the class the manifest's `selector` matches. It's written as a literal rather than through `styles`, so it survives CSS Modules scoping and appears in the rendered DOM.
- `styles.myComponent`: Your own styles from the CSS Module.
- `className`: The styling that Wix users configure in the editor's panels.

The inner elements follow the same pattern, pairing a global class with a module class: `classNames('image', styles.image)`, `classNames('title', styles.title)`, and so on.

This is what the manifest generator reads. It pairs each global class string in your JSX with the matching rules in `<component-name>.module.css`, and writes an entry into the generated `editorElement`. In this component, `'my-component'` becomes the root `selector`, and `'image'`, `'title'`, and `'description'` each become an inner element with the CSS properties its rules imply. An element with only a module class, like the `styles.body` wrapper, doesn't become a manifest element. Use a module class alone for purely structural or decorative elements you don't want Wix users to select.

<blockquote class="important">

**Important:** The root element also carries `id={id}`. The editor needs it to find your component in the page's DOM, and without it your component renders but Wix users can't select it on the stage. Together with a manifest `selector` that matches the root element's global class, this is what makes a component selectable. For more information, see [Make your component selectable](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/about-editor-react-components.md#make-your-component-selectable).

</blockquote>

This is a standard React functional component, so you can use all React features including:

- React hooks like `useState`, `useEffect`, `useCallback`.
- Additional props as needed for your functionality.
- Child components and composition.
- External libraries and SDKs.

## component-name.props.ts

The `<component-name>.props.ts` file holds 2 things: your component's props type, and a `defaultProps` constant with the fallback values for those props.

```typescript
import type { Image, Direction } from '@wix/editor-react-types';

export type MyComponentProps = {
  id?: string;
  className?: string;
  image?: Image;
  title?: string;
  description?: string;
  direction?: Direction;
};

export const defaultProps = {
  title: 'Title',
  description: 'Description goes here',
} as const satisfies Omit<MyComponentProps, 'id' | 'className'>;
```

`defaultProps` is the single source of truth for the default values of your component's props. It's consumed in 2 places:

- **`component.tsx`:** Applies it to the rendered component.
- **`<component-name>.extension.ts`:** Passes it to `withEditorElementDefaults` so the editor panels show the same values.

- **Do:** Set the default once in `defaultProps`.
- **Don't:** Hand-write `defaultValue` into the manifest's data items.

Note that `id` and `className` are excluded from `defaultProps` with `Omit`. Wix always provides those, so they never need a fallback.

## component.tsx

The `component.tsx` file is the entry point for your component. It imports your component from `<component-name>.tsx` and its `defaultProps` from `<component-name>.props.ts`, then wires them together with `withDefaults`.

```typescript
import { withDefaults } from '@wix/react-component-utils';
import Component from './my-component';
import { defaultProps } from './my-component.props';

const MyComponent = withDefaults(Component, defaultProps);

export default MyComponent;
```

<blockquote class="caution">

**Caution:** Don't modify the structure or logic of this file. Write your component code in `<component-name>.tsx` and set your defaults in `<component-name>.props.ts`.

</blockquote>

## component.preview.tsx

The `component.preview.tsx` file is the entry point the editor loads, referenced by `resources.editor.componentUrl`. The CLI generates it wrapped in `withFallbackPlaceholder()`, from `@wix/react-component-utils`:

```tsx
import type { ComponentProps, FC } from 'react';
import { withDefaults, withFallbackPlaceholder } from '@wix/react-component-utils';
import Component from './component';
import { defaultProps } from './component.props';

const ComponentPreview: FC<ComponentProps<typeof Component>> = (props) => (
  <Component {...props} />
);

const ComponentPreviewWithFallback = withFallbackPlaceholder(ComponentPreview, {
  requiredDataFields: ['title'],
  rootClassName: 'my-component',
});

export default withDefaults(ComponentPreviewWithFallback, defaultProps);
```

`withFallbackPlaceholder()` shows a placeholder on the stage instead of your component until every field listed in `requiredDataFields` has a value. The CLI sets `requiredDataFields` once, at scaffold time, to whichever `data` field names existed on your component then.

> **Caution:** If you rename a data field later, `requiredDataFields` doesn't update with it. It keeps checking for the old field name, which no longer exists, so the check never passes. Your component then shows the placeholder permanently, on the stage and in preview, with no error pointing at the cause. After renaming a data field, update `requiredDataFields` in this file to match.

Edit this file further when the component should behave or render differently inside the editor than it does on the live site. Common reasons are supplying mock data so the component looks populated on the stage, showing a specific visual state, or disabling an interaction that would get in the way of editing.

## component-name.module.css

The `<component-name>.module.css` file contains the default styles for the generated component. It uses [CSS Modules](https://github.com/css-modules/css-modules), which scope class names locally to avoid conflicts with other components on the page.

Because CSS Modules scope your class names, the class you write here isn't necessarily the class that appears in the rendered DOM. Your manifest's `selector` has to match what actually renders, so add a plain string class to the elements the manifest targets, alongside your CSS Modules class. For more information, see [Make your component selectable](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/about-editor-react-components.md#make-your-component-selectable).

## See also

- [`wix app generate manifest`](https://dev.wix.com/docs/wix-cli/cli-for-apps/command-reference/project-commands/generate-manifest.md)
- [Manifest Validation and Unsupported Features](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/about-the-manifest.md)
- [Add an Editor React Component Extension with the Wix CLI](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/supported-extensions/site/editor-react-components/add-an-editor-react-component-extension-with-the-wix-cli.md)
- [About Site Extensions](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/about-site-extensions.md)
- [About the Manifest](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/about-the-manifest.md)
- [Installation](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/root-properties/installation.md)
- [Resources](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/root-properties/resources.md)
- [Tutorial | Build a Manifest Step by Step](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/auto-panels/tutorial-configure-auto-panels.md)
- [Runtime Props](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/site-extensions/editor-react-components/manifest-reference/runtime-props.md)
- [About Wix Skills for the CLI](https://dev.wix.com/docs/api-reference/articles/ai-tools/about-wix-skills.md)