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

this.container not working

Open planetwebsolution opened this issue 8 years ago • 3 comments

I got can not read container of undefined. below is my snippet

import { ToastContainer, ToastMessage } from 'react-toastr';

const ToastMessageFactory = React.createFactory(ToastMessage.animation);

addAlert () {
    this.container.success(
      "my-title",
      "my-fascinating-toast-message", {
      timeOut: 5000,
      extendedTimeOut: 3000
    });
  }

render() {
  return (<div>
        <ToastContainer ref={(input) => {this.container = input;}}
                        toastMessageFactory={ToastMessageFactory}
                        className="toast-top-right"
                        preventDuplicates="true" />
        <button onClick={this.addAlert}>Add Toast</button>
      </div>);
}

planetwebsolution avatar Sep 26 '17 14:09 planetwebsolution

@planetwebsolution the documentation says

`let ReactToastr = require("react-toastr") let {ToastContainer} = ReactToastr

let ToastMessageFactory = React.createFactory(ReactToastr.ToastMessage.animation)`

but not sure if that will fix your problems

mclapa avatar Oct 12 '17 00:10 mclapa

Did your console has errors?

tomchentw avatar Oct 12 '17 01:10 tomchentw

You need to import React as well, if you haven't already. The example assumes usage within an existing component.

whns avatar Oct 13 '17 03:10 whns