schiehll / react-alert

alerts for React
MIT License
607 stars 99 forks source link

integration with connect (react-redux) #83

Closed guymalka closed 6 years ago

guymalka commented 6 years ago

can this project work with react-redux? withalert(connect ()()) does not work

schiehll commented 6 years ago

Hey @guymalka, it does work with redux.

Here's an example of how to integrate it with redux: https://codesandbox.io/s/xvr74ln96q

Hope it helps!

shorif2000 commented 5 years ago

@schiehll i have tried this and it is not working

Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Hienphamthe commented 5 years ago

Hi @schiehll, thank you for the codesandbox. However, when I tried to reproduce it on my code, it does not work. The redux compose() is imported as a function, not a HOC, so the Home could not be rendered. The redux package version is the same. Error is returned as below. Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.

schiehll commented 5 years ago

@Hienphamthe if you are using the v5 of this lib, try something like this:

export default compose(
 // See the extra () here? This wasn't needed in previous versions
 withAlert(),
 connect(mapStateToProps),
 ...
)(YourComponent)