我react-toastify在我的 React 應用程式中使用通知。在其配置中,我設定了默認autoClose設定。有沒有一種方法可以僅針對特定通知覆寫此設定?請在下面找到我當前的代碼。
我react-toastify在索引頁面中設定了默認配置:
import { ToastContainer } from "react-toastify";
<ToastContainer
closeButton={false}
autoClose={6000}
/>
例如,在其他頁面上,我的代碼受到了打擊。在那里我想autoClose僅為該特定訊息設定自定義配置。
Notify({
message: `A message`,
});
這使用了一個名為 Notify 的組件:
const User = ({ message, closeToast }) => (
<div key={0} className="notification">
<span style={{ backgroundImage: `url('/icons/user.svg')` }}></span>
<label dangerouslySetInnerHTML={{ __html: message }}></label>
<button onClick={closeToast}> </button>
</div>
);
const Notification = (props) => {
const { message, user } = props;
return (
<div>
toast(<User message={message} />, {
className: "white-background",
bodyClassName: "grow-font-size",
progressClassName: "fancy-progress-bar",
})
</div>
);
};
uj5u.com熱心網友回復:
根據 react-toastify 的檔案,您可以將 autoClose 道具傳遞到 toast() 發射器以及 ToastContainer
toast('My message', {autoClose: 5000});
https://fkhadra.github.io/react-toastify/introduction/
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/449031.html
