Skip to content
Discussion options

You must be logged in to vote

This is expected behavior. The autoplay option sets the initial playing state when the component mounts. When the lightbox mounts with an empty slides array, playing is immediately disabled (no slides to play), and it won't re-activate when slides arrive later.

Here are two recommended approaches:

Option 1: Render the lightbox only when slides are ready

export default function Test() {
  const [slides, setSlides] = useState();

  useEffect(() => {
    axios
      .get("https://picsum.photos/v2/list?page=1&limit=3")
      .then((res) =>
        setSlides(res.data.map((img) => ({ src: img.download_url }))),
      );
  }, []);

  if (!slides) {
    return <div>Loading placeholder</div>;
  }

  

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by realrnvr
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants