Skip to content

Rule proposal: prevent both children and dangerouslySetInnerHTML at the same time #710

Closed
@lencioni

Description

@lencioni

React will issue a warning if you try to use dangerouslySetInnerHTML and children at the same time.

https://github.com/facebook/react/blob/85dcbf83/src/renderers/dom/shared/ReactDOMComponent.js#L170

This should be easy enough to enforce for most cases with a linter rule.

Bad:

<div dangerouslySetInnerHTML={{ __html: 'HTML' }}>
  Children
</div>

Good:

<div dangerouslySetInnerHTML={{ __html: 'HTML' }} />
<div>
  Children
</div>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions