Skip to content

How to use Avatar with NextJS Images #3147

Answered by mulfyx
quangnmwork asked this question in Q&A
Discussion options

You must be logged in to vote

Use getImageProps: https://nextjs.org/docs/app/api-reference/components/image#getimageprops

import { Avatar as ArkAvatar } from "@ark-ui/react";
import { clsx } from "clsx";
import {
	getImageProps as getNextImageProps,
	type ImageProps,
	type StaticImageData,
} from "next/image";

import { type AvatarProps } from "./avatar.types";

import * as styles from "./avatar.css";

function getName(firstName: string, lastName?: string) {
	return lastName != null ? `${firstName} ${lastName}` : firstName;
}

function getInitials(firstName: string, lastName?: string) {
	if (lastName == null) {
		return firstName.slice(0, 2).toUpperCase();
	}

	return `${firstName[0]}${lastName[0]}`.toUpperCase();
}

f…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by segunadebayo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants