Skip to content

Make createMachineComponent use closes fallback #7

@anoukd

Description

@anoukd

When using nested states in createMachineComponent, it would be nice to be able to specify one fallback component on a parent state, which will be used for all nested states that are not defined.

For example, I now have to do this when I want to render one component in all registration states, except loaded.subscribed.unsubscribe:

const RegistrationPageMachineComponent =
  createMachineComponent<RegistrationMachine>({
    Fallback: () => <FallbackComponent />,
    states: {
      loaded: {
        Fallback: () => <FallbackComponent />,
        states: {
          subscribed: {
            Fallback: () => <FallbackComponent />,
            states: {
              unsubscribe: () => <UnsubscribePage />,
            },
          },
        },
      },
    },
  })

Instead of passing the same fallback component three times, it would be nice to just define it on the root:

const RegistrationPageMachineComponent =
  createMachineComponent<RegistrationMachine>({
    Fallback: () => <FallbackComponent />,
    states: {
      loaded: {
        states: {
          subscribed: {
            states: {
              unsubscribe: () => <UnsubscribePage />,
            },
          },
        },
      },
    },
  })

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions