How would I redirect the image url when error is occuring? Because this is not working. I need a solution for 2021.
edit: Since I am mapping through an array. How would I define password before the return function?
          const dispatch = useDispatch();
          const passwordList = useSelector((state) => state.passwordList);
          const { loading, error, passwords } = passwordList;
        
          const [imgSrc, setImgSrc] = useState(
            "`https://example.com/${password.url}`"
          );
        
          const handleError = () =>
            setImgSrc("https://upload.wikimedia.org/wikipedia/commons/c/ce/Example_image.png");
        
 
       <ul >
{passwords.map((password) => (
  <div>
    <li
      key={password.id}
     >
      <img
        src={imgSrc}
        onError={handleError}
      />
    </li>
  </div>
))}
</ul>
        
Here's an example of what I am trying to do: https://jsfiddle.net/maccman/2kxxgjk8/3/
 
    