moroshko / react-autowhatever

Accessible rendering layer for Autosuggest and Autocomplete components

Home Page:http://react-autowhatever.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using async items inside mapDispatchToProps

gusaiani opened this issue · comments

Hi @moroshko,

first, many thanks for react-autowhatever. Great work. And great name.

I’m having difficulties with onMouseDown and onKeyDown(case: 'Enter').
They access items inside mapDispatchToProps, as in items[focusedItemIndex].

My items are loaded asynchronously.
The actions inside mapDispatchToProps can’t find the items, which are Redux state, and they stay undefined.

Any suggestion on how to correctly tie the items coming from the state to those functions?

Here’s my component if you’d like to see the context: https://gist.github.com/gusaiani/afd56e4655e2aca83859

Thanks in advance for your help.

@gusaiani I'd probably have the items you retrieved asynchronously injected to Companies as props via mapStateToProps(). Then, you could use ownProps in mapDispatchToProps() (the second argument) to get those items.

Having said that, it looks like you are trying to implement an Autosuggest component. Have you considered using react-autosuggest?

Btw, how did you find about react-autowhatever's existence?

Thanks, @moroshko, I’ll give that a try.
I found a more verbose to make it work but yeah...need to make it elegant.

I found this lib by googling, really.
I also tried react-autosuggest for a few hours, but to be honest I found it much easier to implement react-autowhatever.
Read the source code for each example and it was quite easy.

For some reason I found the implementation code for autosuggest, in the README and Codepen examples, were harder to learn from.

I’m sticking with this one :)

Thank you again!

@gusaiani Thanks for your feedback.

Thank you.
The lib is "live" at www.lookintens.com as a matter of fact.
The data is not real yet, I will add a disclaimer soon, but autowhatever seems to work very well.

@gusaiani Thanks for the link! FYI, if I press Enter when input is focused, I get a JS error.

Btw, I simplified the API in react-autosuggest recently, so you might want to give it another chance in the future ;)

Thanks, I'll fix that.
Awesome, I'll sure check out react-autosuggest again then.