import * as Cookie from "js-cookie"; import * as React from "react"; import GlobalToast from "./index"; const { Component } = React; export type ToastType = "error" | "info" | "success" | "warning"; export interface IToastState { message: string; url: string; buttonLabel: string; type: ToastType; duration: number; animationDuration: number; visible: boolean; title: string; } export default class GlobalToastFromCookie extends React.Component<{}, IToastState> { constructor(props) { super(props); this.state = { message: "", url: "", buttonLabel: "", type: "success", duration: 5000, animationDuration: 200, visible: false, title: "", }; } public componentDidMount() { const toastCookie = Cookie.get("lpToast"); if (toastCookie) { return this.setState({ ...this.state, ...JSON.parse(toastCookie), visible: true, }); } } public render() { return( { Cookie.remove("lpToast", { domain: ".lonelyplanet.com"}); }} /> ); } }