sstur / react-rte

Pure React rich text WYSIWYG editor based on draft-js.
https://react-rte.org
ISC License
2.86k stars 429 forks source link

Uncontrolled input #310

Closed MariaShyn closed 5 years ago

MariaShyn commented 5 years ago

I'm trying to set a maximum length of value passed to RTE.

handleChangeRte = (value) => {
    const left = this.maxCharacters - value.toString('html').replace(/<(?:.|\n)*?>/gm, '').length;
    if (left >= 0) {
        const updateForm = { ...this.state.form, description: value, left };
        this.setState({ form: updateForm });
    }
};

However, even after state of the component isn't changed, new symbols continue to appear in input while typing.

sstur commented 5 years ago

Hmm, few things wrong with this code. First, this is not an uncontrolled input, it appears to be the opposite. Second there seems to be some state called "form" which has a property "left" which afaik is not a property that can be understood by react-rte, in fact, neither can description.

I'm not sure why your code isn't working, but from looking at this code I don't see any issue with react-rte, so I'm going to close this as nothing wrong.