Skip to content

Make replacing broken profile images with the placeholder smiley work #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cirosantilli opened this issue Dec 28, 2021 · 0 comments
Labels

Comments

@cirosantilli
Copy link
Owner

cirosantilli commented Dec 28, 2021

ac9f885 not working and https://stackoverflow.com/questions/66949606/what-is-the-best-way-to-have-a-fallback-image-in-nextjs/66953317#66953317 did not work on a react 12 hello world with img (not Image):

pages/index.js

import React, { useState } from 'react';
import Image from 'next/image';

const ImageWithFallback = (props) => {
    const { src, fallbackSrc, ...rest } = props;
    const [imgSrc, setImgSrc] = useState(src);
    return (
        <img
          {...rest}
          src={imgSrc}
          onError={() => {
            setImgSrc(fallbackSrc);
          }}
        />
    );
};

export default function IndexPage() {
  return <ImageWithFallback
    key="asdfqwer"
    src="asdfqwer"
    fallbackSrc="https://i.stack.imgur.com/jhDFt.png"
  />
}

package.json

{
  "name": "test",
  "version": "1.0.0",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "next": "12.0.7",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  }
}

The key code point is: https://github.com/cirosantilli/node-express-sequelize-nextjs-realworld-example-app/blob/ac9f885b254fa1baceb21e391a795f5c4c9e6bd6/components/CustomImage.tsx The original code from Chinese author was trying to handle that, but does not seem to be working.

At b278cce at least hidding the alt, but we want the placeholder.

@cirosantilli cirosantilli changed the title Make replacing images with the placeholder smiley work Make replacing broken profile images with the placeholder smiley work Dec 28, 2021
cirosantilli added a commit that referenced this issue Dec 28, 2021
It overflows everywhere and annoys me.

Proper resolution would be to show smiley instead:
#14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant