Giter VIP home page Giter VIP logo

react-alert's Introduction

react-alert

alerts for React

travis build version

Demo

Edit l2mo430lzq

Installation

$ npm install --save react-alert

Templates

You can provide your own alert template if you need to. Otherwise you can just plug in one of the following:

Feel free to submit a PR with the link for your own template.

To get started, try installing the basic one:

$ npm install --save react-alert react-alert-template-basic

Peer dependencies

This package expect the following peer dependencies:

  "react": "^16.8.1"
  "react-dom": "^16.8.1"

So make sure that you have those installed too!

Usage

First you have to wrap your app with the Provider giving it the alert template and optionally some options:

// index.js
import React from 'react'
import { render } from 'react-dom'
import { transitions, positions, Provider as AlertProvider } from 'react-alert'
import AlertTemplate from 'react-alert-template-basic'
import App from './App'

// optional configuration
const options = {
  // you can also just use 'bottom center'
  position: positions.BOTTOM_CENTER,
  timeout: 5000,
  offset: '30px',
  // you can also just use 'scale'
  transition: transitions.SCALE
}

const Root = () => (
  <AlertProvider template={AlertTemplate} {...options}>
    <App />
  </AlertProvider>
)

render(<Root />, document.getElementById('root'))

Then import the useAlert hook to be able to show alerts:

// App.js
import React from 'react'
import { useAlert } from 'react-alert'

const App = () => {
  const alert = useAlert()

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

export default App

And that's it!

You can also use it with a HOC:

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)

Options

You can pass the following options as props to Provider:

offset: PropTypes.string // the margin of each alert
position: PropTypes.oneOf([
  'top left',
  'top right',
  'top center',
  'middle left',
  'middle',
  'middle right',
  'bottom left',
  'bottom right',
  'bottom center'
]) // the position of the alerts in the page
timeout: PropTypes.number // timeout to alert remove itself, if  set to 0 it never removes itself
type: PropTypes.oneOf(['info', 'success', 'error']) // the default alert type used when calling this.props.alert.show
transition: PropTypes.oneOf(['fade', 'scale']) // the transition animation
containerStyle: PropTypes.Object // style to be applied in the alerts container
template: PropTypes.oneOfType([PropTypes.element, PropTypes.func]).isRequired // the alert template to be used

Note that the position, type and transition strings are available as constants which can be imported the next way:

import { positions, transitions, types } from 'react-alert'

and have such values:

export const positions = {
  TOP_LEFT: 'top left',
  TOP_CENTER: 'top center',
  TOP_RIGHT: 'top right',
  MIDDLE_LEFT: 'middle left',
  MIDDLE: 'middle',
  MIDDLE_RIGHT: 'middle right',
  BOTTOM_LEFT: 'bottom left',
  BOTTOM_CENTER: 'bottom center',
  BOTTOM_RIGHT: 'bottom right'
}

export const types = {
  INFO: 'info',
  SUCCESS: 'success',
  ERROR: 'error'
}

export const transitions = {
  FADE: 'fade',
  SCALE: 'scale'
}

Here's the defaults:

offset: '10px'
position: positions.TOP_CENTER
timeout: 0
type: types.INFO
transition: transitions.FADE,
containerStyle: {
  zIndex: 100
}

Those options will be applied to all alerts (please, also have a look at edge-cases)

Api

After getting the alert with the useAlert hook, this is what you can do with it:

// show
const alert = alert.show('Some message', {
  timeout: 2000, // custom timeout just for this one alert
  type: 'success',
  onOpen: () => {
    console.log('hey')
  }, // callback that will be executed after this alert open
  onClose: () => {
    console.log('closed')
  } // callback that will be executed after this alert is removed
})

// info
// just an alias to alert.show(msg, { type: 'info' })
const alert = alert.info('Some info', {
  timeout: 2000, // custom timeout just for this one alert
  onOpen: () => {
    console.log('hey')
  }, // callback that will be executed after this alert open
  onClose: () => {
    console.log('closed')
  } // callback that will be executed after this alert is removed
})

// success
// just an alias to alert.show(msg, { type: 'success' })
const alert = alert.success('Some success', {
  timeout: 2000, // custom timeout just for this one alert
  onOpen: () => {
    console.log('hey')
  }, // callback that will be executed after this alert open
  onClose: () => {
    console.log('closed')
  } // callback that will be executed after this alert is removed
})

// error
// just an alias to alert.show(msg, { type: 'error' })
const alert = alert.error('Some error', {
  timeout: 2000, // custom timeout just for this one alert
  onOpen: () => {
    console.log('hey')
  }, // callback that will be executed after this alert open
  onClose: () => {
    console.log('closed')
  } // callback that will be executed after this alert is removed
})

// remove
// use it to remove an alert programmatically
alert.remove(alert)

// removeAll
// use it to remove all alerts programmatically
alert.removeAll()

Using a custom alert template

If you ever need to have an alert just the way you want, you can provide your own template! Here's a simple example:

import React from 'react'
import { render } from 'react-dom'
import { Provider as AlertProvider } from 'react-alert'
import App from './App'

// the style contains only the margin given as offset
// options contains all alert given options
// message is the alert message
// close is a function that closes the alert
const AlertTemplate = ({ style, options, message, close }) => (
  <div style={style}>
    {options.type === 'info' && '!'}
    {options.type === 'success' && ':)'}
    {options.type === 'error' && ':('}
    {message}
    <button onClick={close}>X</button>
  </div>
)

const Root = () => (
  <AlertProvider template={AlertTemplate}>
    <App />
  </AlertProvider>
)

render(<Root />, document.getElementById('root'))

Easy, right?

Using a component as a message

You can also pass in a component as a message, like this:

alert.show(<div style={{ color: 'blue' }}>Some Message</div>)

Showing alerts in different positions at the same time

First of all, if have a need to separate the logic of showing alerts in different positions at the same time it is possible to use multiple AlertProviders in one project and nest them across the DOM tree. Also you can use different Contexts to get the references to each type of alert separately.

import React, { createContext } from 'react'
import { render } from 'react-dom'
import { useAlert, positions, Provider as AlertProvider } from 'react-alert'
import AlertTemplate from 'react-alert-template-basic'

const TopRightAlertContext = createContext()

const App = () => {
  const alert = useAlert()
  const topRightAlert = useAlert(TopRightAlertContext)

  return (
    <div>
      <button onClick={() => alert.show('Oh look, an alert!')}>
        Show Alert
      </button>
      <button
        onClick={() =>
          topRightAlert.show('Oh look, an alert in the top right corner!')
        }
      >
        Show Top Right Alert
      </button>
    </div>
  )
}

const Root = () => (
  <AlertProvider template={AlertTemplate}>
    <AlertProvider
      template={AlertTemplate}
      position={positions.TOP_RIGHT}
      context={TopRightAlertContext}
    >
      <App />
    </AlertProvider>
  </AlertProvider>
)

render(<Root />, document.getElementById('root'))

Another use case is when you don't want to nest a couple of AlertProviders because it will somehow complicate management of alerts (for example when you need to show alerts in more than three different positions).

In this case you can pass the position directly to the alert. The alerts without individual position property will take it from the Provider. Instead, passing the position to methods show, success, info, error will overlap the Provider's position.

Passing the property position will look like this:

alert.show('Oh look, an alert!', { position: positions.BOTTOM_LEFT })

An example of showing alerts simultaneously in three different positions:

import React from 'react'
import { render } from 'react-dom'
import {
  Provider as AlertProvider,
  useAlert,
  positions,
  transitions
} from 'react-alert'
import AlertTemplate from 'react-alert-template-basic'

const alertOptions = {
  offset: '25px',
  timeout: 3000,
  transition: transitions.SCALE
}

const App = () => {
  const alert = useAlert()

  const showAlert = () => {
    alert.show('Oh look, an alert!', { position: positions.BOTTOM_LEFT }) //alert will be shown in bottom left
    alert.show('Oh look, an alert!', { position: positions.BOTTOM_RIGHT }) //alert will be shown in bottom right
    alert.show('Oh look, an alert!') //alert will use the Provider's position `top right`
  }

  return <button onClick={showAlert}>Show Alert</button>
}

const Root = () => (
  <AlertProvider template={AlertTemplate}>
    <AlertProvider
      template={AlertTemplate}
      position={positions.TOP_RIGHT} //default position for all alerts without individual position
      {...alertOptions}
    >
      <App />
    </AlertProvider>
  </AlertProvider>
)

render(<Root />, document.getElementById('root'))

react-alert's People

Contributors

ai avatar aj1402 avatar anthonyraymond avatar beslisbeth avatar danielfroz avatar davidhu2000 avatar dennybiasiolli avatar eliyabar avatar felipedeboni avatar guludo avatar mayyyc avatar mperitz avatar rj-david avatar samuelepapa avatar schiehll avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-alert's Issues

Not compatible with Next.js - render blank page on client side

Trying to use react-alert with Nextjs. I copied the example to wrap my page with <AlertProvider />. However, if I hit / link on the client side when I'm already on /, it will render a blank page. The same is true if I go to any route I'm already on.

Please clone an example repo https://github.com/flexlee/nextjs-react-alert. And run yarn, yarn start. In the browser, if you click the "home" link, you will see a blank page.

Alerts forever (does not close) when with multiple components including shared

Suppose I'm on page # 1 and I have a button, I can click it; an alert will show up and a click will take me to page # 2.

In case if page # 2 does make an use of withAlert and there's a shared component that uses withAlert as well, then an alert stays forever.

<SharedComponent> <-- uses withAlert
  <Page1/> <-- uses withAlert
  <Page2/> <-- uses withAlert
</SharedComponent>

I have attached a sample project, which you can run by issuing yarn start
You can click on Click to alert and go to /page and an alert is not going to leave.

alerts-forever.zip

alerts-forever

If you remove withAlert from SharedComponent or Page2 then all is fine, but in my real project, I'm using this.props.alert in both, header and other page.

Currently I have solved this by leaving withAlert only in shared component (Header in my case), and using this.context.alertContainer in place of this.props.alert in other files.

static contextTypes = {
        alertContainer: PropTypes.object
};

Add some class to main Alert wrapper

It would be great to have some class in the place, where all options for Alert (offset, timeout, etc) are applied.
image
For example, I want to increase z-index of my Alert and I have no way to do this due to the stacking context, because my AlertTemplate with my styles is inside this div with options and style position: fixed.

Usage example code mistake

README.md Example section code has mistake.

from

const options = {
  position: 'bottom center',
  timeout: 5000,
  offset: 30, // number is invalid
  transition: 'scale'
}

to

const options = {
  position: 'bottom center',
  timeout: 5000,
  offset: '30px', // PropTypes.string
  transition: 'scale'
}

thank you team!

Extensions incompatible with react-helmet

Hi @schiehll ! Thanks for this extension.

Im using this one with react-helmet and react-router, so this is the Root component structure for render:

image

so, with this structure im getting empty tags for react-helmet under the SSR. but when page loads in browser - seems all tags are on their place.

when im trying to remove AlertProvider - all tags are appearing as well

can u check what is the problem about ?
Thank u!

Problem when using withAlert() in muliple components

Hi, there.

react-alert behaves inconsistently when more than one component using the withAlert() HoC. The following link can be checked to reproduce the problem: https://codesandbox.io/s/w6l7pz9j9w

I'm also posting part of the source here:

import React, { Component, Fragment } from 'react'
import { withAlert } from 'react-alert'

const Foo = ({alert}) => (<button onClick={() => { alert.info('Foo') }}>Foo</button>);
const FooWithAlert = withAlert(Foo);

const Bar = ({ alert }) => (<button onClick={() => { alert.info('Bar') }}>Bar</button>);
const BarWithAlert = withAlert(Bar);

class Home extends Component {
  state = { now: Date.now() }

  render () {
    return (
      <div>
        <FooWithAlert />
        <BarWithAlert />
        <br />
        <button onClick={() => {this.setState({ now: Date.now() })}}>
          Render wrapping component
        </button>
      </div>
    )
  }
}


export default Home

If you use one of the buttons Foo or Bar and then click in Render wrapping component, the previous alert(s) will be shown.

I've fixed the problem and will raise a pull request shortly.

Best regards,
Gustavo Sousa

Calls setState after parent component unmounts

I have 4 pages, each with the AlertContainer.

If I start an alert on one page, then switch to another page before the alert completes, the timeout of the previous page's alert container will still run and try to call setState, causing an error/warning:

"Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.". 

It would be nice to have a method available on the AlertContainer to clear it's timeout prematurely so that on my parent component's componentWillUnmount lifecycle method I can stop the timeout from continuing to run.

Thanks

ract-alert doesn't work with ssr

Hello, seems that react-alert doesn't work with SSR and react 16.2.0! Any suggestion?
It seems that whatever I wrap in AlertProvider it doesn't renderToString.

How do I trigger alert without button

So far I can use this module run perfectly with example given in readme. But what I want is display this alert based on another props. Here's what I've try :

<div className='col-sm-4'>
    { this.props.alert.show('msg', { type: 'success' }) }
</div>

It gives me this errors, I use create react app.

Objects are not valid as a React child (found: object with keys {id, message, options, close}). If you meant to render a collection of children, use an array instead.
in div (at App.js:23)
    in div (at App.js:22)
    in div (at App.js:18)
    in div (at App.js:17)
    in App (created by WithAlert(App))
    in WithAlert(App) (at index.js:17)
    in AlertsBroadcast (created by Provider)
    in Provider (at index.js:16)
    in Root (at index.js:21)

So, how do I display alert without button?

Custom style

How about custom style for alert? Like text-transform and other.

Pressing on the close button resulting in error

Pressing the close button resulting in [AlertContainer.js] _onremoveAlert() calling twice (one by the user's clicking action, and another because of the setTimeOut in AlertMessage.js

During the second time,

alertRemoved would have been removed from this.state and thus undefined when it reaches this statement:
alertRemoved.onClose && alertRemoved.onClose()

Probably should write it as:

alertRemoved && alertRemoved.onClose && alertRemoved.onClose()

ssr

hi! thanks for this extension.
still not working on server side, can u fix it?

getting browserify error

I'd love to use react-alert, but getting the following error:

Browserify Error { Error: Cannot find module '!!./../../../node_modules/css-loader/index.js!./../../../node_modules/postcss-loader/index.js!./../../../node_modules/stylus-loader/index.js!./alert.styl' from '/var/www/dev.budgetpedia.ca/node_modules/react-alert/dist'

I have react, react-dom and react-addons-css-transition-group as specified.

Any ideas?

Close button does not appear on Firefox 54.0 on Ubuntu 16.04

On Firefox close button seems to not display svg button because of way of implementation:
background-image: url(data:image/svg+xml;utf8,<svg fill=\"#fff\" xmlns=\"http://www.w3.org/2000/s….83-2.83-11.17-11.17z\"/><path d=\"M0 0h48v48h-48z\" fill=\"none\"/></svg>);. In my opinion, solution with ReactSVG with passing styles via className refers to developer chosen color could be better.

Feature Request - Adding sound to alert

I have been using react-alert in one of my projects and have found it rally helpful. I thinking adding sound to the alert will be a really good improvement. I would like to work on this feature myself but I am very new to React and Open Source so I would appreciate some help.

how to use this component when server render

I want to use this component in my project,but as I use server render so when include this packages the project failed as below:

 ReferenceError: document is not defined 
 ReferenceError: window is not defined 

how can i fix it?

Error when loading the library in server side

By just requiring the library in server side, it throws an error.

I don't have the error here, but is something trying to access the window variable in a line that makes a regex.

render blank when setState call

I found the code in Provider.js

 if (this.state.isClient && !this.alertRootElement) {
      this.alertRootElement = document.createElement('div')
      document.body.appendChild(this.alertRootElement)
    } else {
      return null
    }

I use the react-alert like example

render(){
  return (
      <AlertProvider template={AlertTemplate} {...options}>
        <App />
      </AlertProvider>
    )
}

when I setState the state of App and the render function start to run . The logic of alert provider would return null and page render blank.

I update the componentWillUpdate logic same with the componentWillUnmount of the provider. It seems works right.

What should I do for this ? Is there anything I mistake ? @schiehll

Close Calback

Hi!
Any chance to have a close callback fired when the messages disappear?

Thanks

Integration with Redux

Hi !
Thanks a lot for this great resource. This is exactly what I was looking for.
I am using Redux to manage my app's state. Do you have an idea of the best way to use this with React ? I want to avoid duplicating the <AlertContainer /> component when I need my containers to trigger some alerts.

Thanks !

License clarification?

@schiehll this library looks really great! Will you be adding a software license text? I'll be unable to use it at work without it.

É muito legal, valeu!

v3 and light theme

I like react-alert.
But where is light theme??? The dark theme is too gloomy....

Stateless function components cannot have refs

It seems that the Alertcontainer is not a stateful component.

This causes an issue when defining ref="" in recent React implementations and react complains:

Uncaught Error: Stateless function components cannot have refs.
    at invariant (invariant.js:44)
    at ReactCompositeComponentWrapper.attachRef (ReactCompositeComponent.js:846)
    at Object.addComponentAsRefTo (ReactOwner.js:69)
    at attachRef (ReactRef.js:23)
    at Object.ReactRef.attachRefs (ReactRef.js:42)
    at ReactCompositeComponentWrapper.attachRefs (ReactReconciler.js:23)
    at CallbackQueue.notifyAll (CallbackQueue.js:76)
    at ReactReconcileTransaction.close (ReactReconcileTransaction.js:80)
    at ReactReconcileTransaction.closeAll (Transaction.js:206)
    at ReactReconcileTransaction.perform (Transaction.js:153)
...

I'm not sure because I could not get it to work on the cloned repository but it seems that to be a stateful React.Component you need to initialize the state using either the constructor or the getInitialState() method...

So instead of:

  state = {
    alerts: []
  }

do:

constructor (props) {
  super(props)
  this.state = {alerts: []}
}

or

getInitialState() {
  return {alerts: []}
}

but for some reason in my tests when trying that, I still get the error.

Btw, on a side note you are doing this:

this.setState(prevState => ({
  alerts: prevState.alerts.concat(alert)
}))

and thus mutating the state instead of creating a new instance of it:

this.setState(prevState => ({
  alerts: [...prevState.alerts, alert]
}))

using the ES6 spread operator. I think your remove method is actually OK as Array.filter actually creates a new Object.

position option not working

I am unable to get the position option to render correctly. Here is my showAlert function:

showAlert() { this.msg.success('SNAPSHOT ADDED SUCCESSFULLY!', { time: 50000, type: 'success', transition: 'scale', theme: 'light', position: 'top right', }); }

Cannot find module for alert.styl

Error: Cannot find module '!!./../../../node_modules/css-loader/index.js!./../../../node_modules/postcss-loader/index.js!./../../../node_modules/stylus-loader/index.js!./alert.styl'

I'm still getting this error when I include your module and build my project. I know this is the possibly duplicate of #2, but It is not solved yet. How can I fix it? Could you mind including your modules inside my project and build with my components? Of course, I will make clear this component is 100% your creation.

Auto Alert On Page Load

Thanks for creating this great project, I found it really useful!
I was wondering how you recommend if I want to go about loading it directly as soon as the page loads (instead of on button click).

When I try loading it in componentWillMount I can't get it working. Any advice?

Create generic Alert component

Hi, I'm in trouble on generalizing this component.

Let's say I got same App example in main page, renaming class as "MyAlert" and I put it inside a MyAlert.js file.
Then I would like to use it from other components...

If I import my custom alert component file like this:
import MyAlert from './MyAlert';
I've tried to do something like:

 functionCallAlert(){    
		 MyAlert.showAlert;
 }

But nothing happens. I don't want to put all the alert code in every component, is there a way to create a generic-importable component?

thanks

Question: CSS strange classnames...

Hello,

Thanks for the great and very useful lib.

I've noticed that in the latest version (v2.0.1), I don't see the expected classes (react-alerts) on the DOM element.
I'm wondering if I've done something wrong for that to happen...
On the demo application, it works properly, in my previous application, it also worked fine and now here I have this:

<div class="css-5wn51h">
  <span>
    <div class="css-1vm9g5e">
      <div class="css-1vuw43k">
        <div class="css-1f1jd2h"></div>
      </div>
      <div class="css-6bx4c3">Fetching node info for internal, 9702069 failed: 404 -&gt; Not Found</div>
      <div class="css-1lf6zld"></div>
    </div>
  </span>
</div>

image

const alertOptions = {
  offset: 10,
  position: 'bottom right',
  theme: 'dark',
  time: 0,
  transition: 'fade'
}
...
<AlertContainer className='Alerts' ref={(a) => global.msg = a} {...alertOptions} />

Even the className set on the container element does not seem to appear.
In the react tab of the developer tools in Chrome I correctly see it however.

image

Any ideas?

Cannot find module 'react-addons-css-transition-group'

When installed with npm i react-alert --save I get the error Cannot find module 'react-addons-css-transition-group'. My npm version is npm: '3.5.2'

When I call npm install react-addons-css-transition-group --save I get the error

Cannot find module '!!./../../../node_modules/css-loader/index.js!./../../../node_modules/postcss-loader/index.js!./../../../node_modules/stylus-loader/index.js!./alert.styl''

position top center

Hi guys is there some way for get the position top center? I have been watching the code, but I have couldnt reach. Could you help me? Thanks

Use React context for accessing message service

What do you think about moving to a context-based AlertContainer with injection of the message service via a higher-order component?

High-level view of what I'm suggesting (very similar to how react-intl works):

import {AlertProvider, injectAlert} from 'react-alert'

export class App extends Component {

    render() {
        return (
            <AlertProvider>
                <Sidebar />
                <Content>
                    <Home />
                </Content>
            </AlertProvider>
        )
    }
}

@injectAlert
class Home extends Component {

    _alert = () => {
        // this.props.alert is provided by injectAlert higher-order-component which knows which AlertProvider
        // to work against via React context
        this.props.alert.show(<DummyAlert />)
    }

    render() {
        <div className='Home'>
            <button onClick={this._alert}>Alert!</button>
        </div>
    }
}

const DummyAlert = () => (
    <h1>Hello world</h1>
)

Pros of this is no need to work against both the React ref API as well as react-alert's component class itself (both being a bit of an anti-pattern in React-world). It's also much easier to consume this library by being able to inject the alert service where it's needed, without having to pass it as a prop through the entire component tree.

TypeError: Object(...) is not a function

Getting TypeError: Object(...) is not a function when trying to implement this per the demo. Simply adding

import { Provider } from "react-alert";
import AlertTemplate from "react-alert-template-basic";

to the top of my file causes the error

Can i change the look and feel of the component apart from the available themes? can i have this component wrapped in a component like card?

i want to have green color border and background fill for success; red color for error, yellow color for warning and blue color for info. Is it possible to customize this component like that? please, let me know if there are any workaround possible.

Also please let me know if i can position this component inside a card apart from the positioning options available? I placed the alert component inside card. but the alert is always getting displayed outside the card.
Thanks.

Icon images not loading

Hey,

Great alert lib by the way!

The icons are not loading for me when I use the example in the readme.

Do I need to include anything aside from the example code?

Is it possible to have font icons in the icon?

Thanks in advance!

Warning: Can't call setState (or forceUpdate) on an unmounted component.

When timeout has not elapsed yet and the component is unmounted, I'm getting this error once the timeout elapsed.

Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
    in Provider (created by ComponentWithDefaultLayout)

Error icon

Hey, i've got a little problem with the icon.
icon

My Code:

import React from 'react';
import AlertContainer from 'react-alert';

export default class App extends React.Component {
constructor(props){
super(props);
this.alertOptions = {
offset: 10,
position: 'top',
theme: 'dark',
time: 5000,
transition: 'scale'
};
}
showAlert(){
this.msg.info('Connected', {
time: 5000,
type: 'info',
icon: <img src="img/error.png" alt="" />
});
}
render(){
return(
<div>
<AlertContainer ref={a => this.msg = a} {...this.alertOptions} />
<button onClick={this.showAlert.bind(this)}>Show Alert</button>
</div>
);
}
}

I cant find out the problem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.