Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

reactjs - Includes function not picking up on .mov text in url

Here is my url:

https://firebasestorage.googleapis.com/v0/b/roger.appspot.com/o/images%2Fd4%2FIMG_6538.mov?alt=media&token=19f7b5e7-77d6-480e-97f1-55ad9d27bb08

I'm using includes to run over the URL to find mov

However, my function returns null

// check media url to see if link left should render video or image
  useEffect(() => {
    async () => {
      if (imageUrl) {
        const isVideo = await imageUrl.includes("mp4", "mov", "MOV");

        if (isVideo) {
          return setMediaType("video");
        }
        setMediaType("image");
      }
    };
  }, [imageUrl]);

When I console log mediaType I get null


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you are not doing it right

useEffect(() => {
(async () => {
  if (imageUrl) {
                    // Why are you using await here

    const isVideo = imageUrl.includes("mp4", "mov", "MOV");

    if (isVideo) {
      return setMediaType("video");
    }
    setMediaType("image");
  }
})();

}, [imageUrl]);


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...