Updating animation swipe duration from a custom toolbar button #293
-
Hi, Apologies if this is a noob question; I'm completely new to React. What I'm trying to add is a toolbar button that toggles the lightbox's I have tried passing the Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi there! Unless you are building a reusable plugin, there is an easier way to implement this. You just need to create a state variable to store your swipe duration and read the initial value in a layout effect. You can add your custom button through the const [swipe, setSwipe] = useState(400);
useLayoutEffect(() => {
const swipeValue = localStorage.getItem("swipe");
if (swipeValue) {
setSwipe(Number.parseInt(swipeValue, 10));
}
}, []);
const toggleSwipe = () => {
const swipeValue = swipe === 0 ? 400 : 0;
setSwipe(swipeValue);
localStorage.setItem("swipe", `${swipeValue}`);
};
// ...
<Lightbox
// ...
animation={{ swipe }}
toolbar={{
buttons: [
<button key="swipe" type="button" className="yarl__button" onClick={toggleSwipe}>
{swipe} ms
</button>,
"close",
],
}}
/> |
Beta Was this translation helpful? Give feedback.
Hi there! Unless you are building a reusable plugin, there is an easier way to implement this. You just need to create a state variable to store your swipe duration and read the initial value in a layout effect. You can add your custom button through the
toolbar.buttons
prop.