I get the following warning when rendering my component:
Warning: A component is
contentEditable
and containschildren
managed by React. It is now your responsibility to guarantee that none of those nodes are unexpectedly modified or duplicated. This is probably not intentional.
This is my component:
import React, { Component } from "react";
export default class Editable extends Component {
render() {
return (
<div contentEditable={true} onBlur={this.props.handleBlur}>
{this.props.children}
</div>
);
}
}
What is the potential problem with my code that React wants to warn me about? I did not quite understand from reading the documentation at https://reactjs.org/docs/dom-elements.html.
I imagine that my component should work exactly like an managed input field, without any problem:
this.props.children
is initial value- the
onBlur
callback updates the props fromevent.target.innerHTML
- the component is rendered with the new props
this.props.children
, it only knows that you can destroy those props. There are consequences for all sorts of things. If there are event subscriptions, they could become memory leaks, if there are bound properties they could become danglers, etc. As zzzBov said, don't shoot yourself in the foot. It doesn't sound like you will, but neither React nor we can know that. – Randy Casburn