webscopeio / react-textarea-autocomplete

📝 React component implements configurable GitHub's like textarea autocomplete.
MIT License
451 stars 80 forks source link

Set a predefined value inside the textarea #151

Closed teilzeitgeist closed 5 years ago

teilzeitgeist commented 5 years ago

Hey @jukben,

I wanna set a predefined value (autosave feature) for the textarea.

In #141 you mentioned it's the best way to change the value of the component ( <ReactTextareaAutocomplete value={this.state.text} ... />) and this.setState({text: value}).

So I use setState in the componentDidMount() function and I get everytime the same error:

Uncaught TypeError: Cannot read property 'selectionEnd' of null at ReactTextareaAutocomplete._this2._changeHandler (react-textarea-autocomplete.es.js:1028) at ReactTextareaAutocomplete.componentDidUpdate (react-textarea-autocomplete.es.js:1287) at commitLifeCycles (react-dom.development.js:17349) at commitAllLifeCycles (react-dom.development.js:18736)

The problem is probably a triggered custom "change" event, which has no target.

Sorry, I can't reproduce this error in a clean environment because my application is too complex. Maybe we can build in a check if the event has a target or not?

teilzeitgeist commented 5 years ago

It's probably not an issue of your component. I need to figuring out, what is bubbling the custom change event, which has no target.

jukben commented 5 years ago

If you will figure out what might be an issue, or how to prevent it, feel free to post it here, please 🙏

teilzeitgeist commented 5 years ago

The problem appears when you try to change the value of a textarea (for example via redux) but addresses more than one textarea by mistake (every textarea needs a clear identifier).