schiehll / react-alert

alerts for React
MIT License
608 stars 98 forks source link

How to use it inside a class component #116

Closed B-sirius closed 5 years ago

B-sirius commented 5 years ago

Here is the example. I wanna use it inside a class component, and get the error "Hooks can only be called inside the body of a function component". I'm not sure if there's a problem with my code or if it's only supporting usage in function component

mikhailrojo commented 5 years ago

Hi B-seirius use withHook

import { withAlert } from "react-alert";
...
export default withAlert()(Home)

and invoke it with

this.props.alert.show()
B-sirius commented 5 years ago

Hi B-seirius use withHook

import { withAlert } from "react-alert";
...
export default withAlert()(Home)

and invoke it with

this.props.alert.show()

that works! thanks for helping

luizhenriquerosa commented 5 years ago

Sorry, for me dont work this.props.alert.show()

besLisbeth commented 5 years ago

Hi, @luizhenriquerosa.

Can you please provide the sandbox with an example?