marmelab/react-admin · error

When using a custom Resource element, it must have a static

Error message

When using a custom Resource element, it must have a static registerResource method accepting its props and returning a ResourceDefinition

What it means

react-admin allows passing a custom element as a child of <Admin> in place of <Resource>. Such a custom component must expose a static registerResource(props, permissions) method that returns a ResourceDefinition, because useRegisterResources relies on it to build the resource definitions. When the child element's type has neither a name (standard Resource) nor a registerResource static, this error is thrown.

Source

Thrown at packages/ra-core/src/core/useConfigureAdminRouterFromChildren.tsx:218

const useRegisterResources = (
    resources: (ReactElement & ResourceWithRegisterFunction)[],
    permissions: any
) => {
    const { register, unregister } = useResourceDefinitionContext();

    useEffect(() => {
        resources.forEach(resource => {
            if (
                typeof (
                    resource.type as unknown as ResourceWithRegisterFunction
                ).registerResource === 'function'
            ) {
                const definition = (
                    resource.type as unknown as ResourceWithRegisterFunction
                ).registerResource(resource.props, permissions);
                register(definition);
            } else {
                throw new Error(
                    'When using a custom Resource element, it must have a static registerResource method accepting its props and returning a ResourceDefinition'
                );
            }
        });
        return () => {
            resources.forEach(resource => {
                if (
                    typeof (
                        resource.type as unknown as ResourceWithRegisterFunction
                    ).registerResource === 'function'
                ) {
                    const definition = (
                        resource.type as unknown as ResourceWithRegisterFunction
                    ).registerResource(resource.props, permissions);
                    unregister(definition);
                } else {
                    throw new Error(
                        'When using a custom Resource element, it must have a static registerResource method accepting its props and returning a ResourceDefinition'

View on GitHub (pinned to 051f511bb0)

Solutions

  1. Add a static registerResource method to the custom component: `MyResource.registerResource = ({ name, ...props }, permissions) => ({ name, ...props });`
  2. Alternatively use the standard `<Resource name="..." list={...} />` element instead of a custom component
  3. Type the component as `ResourceWithRegisterFunction` (FunctionComponent & { registerResource }) so TypeScript enforces the static method
  4. If you only need custom props, keep <Resource> and configure it via its props rather than replacing it

Example fix

// before
const CustomResource = (props) => <Resource {...props} />;
<Admin>{<CustomResource name="posts" list={PostList} />}</Admin>

// after
const CustomResource: ResourceWithRegisterFunction = (props) => <Resource {...props} />;
CustomResource.registerResource = (props, permissions) => ({ name: props.name, list: props.list });
<Admin><CustomResource name="posts" list={PostList} /></Admin>
Defensive patterns

Strategy: validation

Validate before calling

if (typeof CustomResource.registerResource !== 'function') {
  throw new Error(`${CustomResource.name} must define a static registerResource method`);
}

Type guard

const isResourceWithRegister = (el: any): el is React.ReactElement & { type: { registerResource: (props: any, permissions: any) => ResourceDefinition } } =>
  React.isValidElement(el) && typeof (el.type as any)?.registerResource === 'function';

Prevention

When it happens

Trigger: Passing a custom React component as a direct child of <Admin> (or <AdminRouter>) whose component does not define `MyComponent.registerResource = (props, permissions) => ({ name, ... })`. Also occurs when permissions are provided and the component lacks the static method during re-registration on permission changes.

Common situations: Building custom resource wrappers or higher-order components around <Resource>; upgrading react-admin where resource children switched from name-based props to ResourceDefinition registration; TypeScript components declared without the static member so the cast fails at runtime.

Related errors


AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30). Data as JSON: /api/errors/dfd6242102d726e5. Report an issue: GitHub.