Skip to content

BlockRenderer type can be null #132

@nilaratna

Description

@nilaratna

I have a case where I need to conditionally skip the custom render when using a custom block renderer map. The code already supports the ability to skip if null is returned but this is blocked by type linting. Can we make changes to the TypeScript and Flow definitions to allow BlockRenderer to be string or null. This is my sample code:

blockRenderers: {
    unstyled: (block: Draft.ContentBlock): string | null => {
      if (block.getText().trim() === '') {
        return '';
      }
      return null;
    }
  }

I can open a PR to do this but wanted to see if there were any arguments against this first.

The change would be to

type BlockRenderer = (block: draftjs.ContentBlock) => string;
and
type BlockRenderer = (block: ContentBlock) => ?string;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions