react-typeahead icon indicating copy to clipboard operation
react-typeahead copied to clipboard

defaultValue doesn't update after re-render

Open yasenov-casafari opened this issue 9 years ago • 2 comments

I have Typeahed object with defaultValue prop. In componentDidMount I receive new value and call setState but defaultValue doesn't change.

yasenov-casafari avatar Sep 07 '15 13:09 yasenov-casafari

same problem here

mCzolko avatar Oct 08 '15 12:10 mCzolko

You may be falling for https://facebook.github.io/react/tips/props-in-getInitialState-as-anti-pattern.html . There's an unofficial API for setting the text: https://github.com/fmoo/react-typeahead/blob/master/src/typeahead/index.js#L108 I don't exactly know how it works in your case for componentDidMount, but for componentDidUpdate, something like this should work:

componentDidUpdate (prevProps, prevState){
  if (this.props.text != prevProps.text) { this.refs.MyTokenizer.setEntryText(this.props.text);}
}

I'd love a readme update PR if you get that working.

trshafer avatar Oct 24 '15 17:10 trshafer