M
M
mosikus2019-12-04 18:25:43
React
mosikus, 2019-12-04 18:25:43

How to "refresh" an image after the user opened the page offline?

Hello. Let's say a user logged into the panel with the Internet disabled - the onError event fired. Is there any way to reload this image?

const [isLoading1, setLoading1] = React.useState(true);
  const [isError1, setError1] = React.useState(false);
  const handleOnLoad1 = () => {
    setLoading1(false);
    setError1(false);
  };
  const handleOnError1 = () => {
    setLoading1(false);
    setError1(true);
  };

<div>
      {isError1 && <div>*Заглушка*</div>}
      {isLoading1 && <div>*Загрузка*</div>}
      <img
        alt="Флаг"
        onError={handleOnError1}
        src="https://mirpozitiva.ru/uploads/posts/2016-08/medium/1472042492_01.jpg"
        height="100"
        style={{ display: isError1 || isLoading1 ? "none" : "block" }}
        onLoad={handleOnLoad1}
      />
    </div>

*The code*

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2019-12-04
@miraage

Online and offline events

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question