From 56961a448c3c080d123393f138b22d67032fae1b Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 15 Aug 2021 02:24:10 -0400 Subject: [PATCH] Update AvatarImageView --- .../shared/avatar-image/AvatarImageView.tsx | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/views/shared/avatar-image/AvatarImageView.tsx b/src/views/shared/avatar-image/AvatarImageView.tsx index a2a5ab56..ea9a823d 100644 --- a/src/views/shared/avatar-image/AvatarImageView.tsx +++ b/src/views/shared/avatar-image/AvatarImageView.tsx @@ -1,21 +1,23 @@ import { AvatarScaleType, AvatarSetType } from '@nitrots/nitro-renderer'; -import { FC, useEffect, useState } from 'react'; +import { FC, useEffect, useRef, useState } from 'react'; import { GetAvatarRenderManager } from '../../../api'; import { AvatarImageViewProps } from './AvatarImageView.types'; export const AvatarImageView: FC = props => { const { figure = '', gender = 'M', headOnly = false, direction = 0, scale = 1 } = props; - const [ avatarUrl, setAvatarUrl ] = useState(null); const [ randomValue, setRandomValue ] = useState(-1); + const isDisposed = useRef(false); useEffect(() => { - if(randomValue) {} - const avatarImage = GetAvatarRenderManager().createAvatarImage(figure, AvatarScaleType.LARGE, gender, { - resetFigure: figure => setRandomValue(Math.random()), + resetFigure: figure => { + if(isDisposed.current) return; + + setRandomValue(Math.random()); + }, dispose: () => {}, disposed: false }, null); @@ -35,6 +37,16 @@ export const AvatarImageView: FC = props => avatarImage.dispose(); }, [ figure, gender, direction, headOnly, randomValue ]); + useEffect(() => + { + isDisposed.current = false; + + return () => + { + isDisposed.current = true; + } + }, []); + const url = `url('${ avatarUrl }')`; return
;