Skip to content

How to have the caption not show by default? #279

Answered by igordanchenko
Fexxix asked this question in Q&A
Discussion options

You must be logged in to vote

Hi there! Thank you for bringing up this use case. While it's possible to eliminate the initial captions flash in the current version, the DX is far from perfect.

const [index, setIndex] = React.useState(-1);
const hideCaptions = React.useRef(false);

const handleCaptionsRef = React.useCallback(
  (captionsRef: CaptionsRef | null) => {
    if (captionsRef && hideCaptions.current) {
      hideCaptions.current = false;
      captionsRef.hide();
    }
  },
  []
);

// ...

<Lightbox
  index={index}
  plugins={[Fullscreen, Captions]}
  captions={{ ref: handleCaptionsRef, showToggle: true }}
  on={{
    entering: () => {
      hideCaptions.current = true;
    },
  }}
  slides={slides.map((slide) 

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Fexxix
Comment options

@igordanchenko
Comment options

@igordanchenko
Comment options

Answer selected by Fexxix
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