I need help with the following:
I would like for the footer to be displayed but when the toast is open, I would like the footer to not display. And when the toast dissapears, after a few seconds(default behavior), the footer needs to come back.
Can someone help me? I am new to React.
The Toast is from bootstrap but with some custom changes. It is working fine rightnow(shows and hides when it is supose to). The state, etc for the toast is in redux.
Below is the code:
<Toast toastStore={toast} showToast={() => toast.open} />
{toast.open ? null : (
<footer className="footer sticky-bottom bg-white d-flex align-items-center w-100">
<div className={`row ${styles.footerRow}`}>
<div className="col-6 d-flex align-items-center justify-content-start">
<Link to="/employees">
<button
className={`btn btn-outline-dark ${styles.backButtton}`}
>
<ChevronLeft />
<span className="fw-bold fs-20">一覧に戻る</span>
</button>
</Link>
</div>
<div className="col-6 d-flex align-items-center justify-content-end">
<button
className={`btn btn-primary fw-bold fs-20 ${styles.registerButton}`}
type="submit"
onClick={handleForm}
>
登録
</button>
</div>
</div>
</footer>
)}
Any kind of workaround would be helpful.
Thank you in advance.
2
Answers
Try using a state to save the value of toast
then use that value
Also use setIsToastOpened to open and close your toast like
To achieve the desired behavior, you can update your code as follows:
true
to display the footer.false
to hide the footer.setTimeout
function to wait for a few seconds (the default behavior of the toast), and then update the state back totrue
to show the footer again.Here’s an example implementation:
In the code above, the
showFooter
state is used to conditionally add thed-none
class (which sets thedisplay
property tonone
) to the footer component. When the toast is open, the footer will be hidden, and after the toast disappears, the footer will be displayed again.Make sure to adjust the timeout value in the
setTimeout
function to match the duration of the toast visibility.Note: If you’re using Redux to manage the toast state, you can access the toast state from the Redux store in your component and use it accordingly.