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

How do I trigger an alert as a function?

Open sonnyboy27 opened this issue 4 years ago • 1 comments

I'm trying to update an old application that I inherited that was using 2.4. Much of the code is triggering the alerts through a callback function after a fetch. These data calls are completely divorced from the page/render context so I'm not sure how to get the reference with the new hooks setup.

sonnyboy27 avatar Jul 21 '21 16:07 sonnyboy27

Hi @sonnyboy27, did you try to use HOCs as in the example below?

import React from 'react'
import { withAlert } from 'react-alert'

const App = ({ alert }) => (
  <button
    onClick={() => {
      alert.show('Oh look, an alert!')
    }}
  >
    Show Alert
  </button>
)

export default withAlert()(App)

besLisbeth avatar Sep 21 '21 09:09 besLisbeth