Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
React CSSTransition and conditional rendering

I'm trying to animate the component on page. It's rendering conditional, so when the data is loading we can see the spinner. How to add animation after successful upload? To be precise, I don't know which inProp I should use. I tried it with "loading" but it didn't work.

const SingleComicPage = () => {
const {comicId} = useParams();
const [comic, setComic] = useState(null);
const {loading, error, getComic, clearError} = useMarvelService();



useEffect(() => {   // eslint-disable-next-line
    updateComic();  // eslint-disable-next-line
}, [comicId]);      // eslint-disable-next-line

const updateComic = () => {
    clearError();
    getComic(comicId)
        .then(onComicLoaded)
}

const onComicLoaded = (comic) => {
    setComic(comic);
}

const errorMessage = error ? <ErrorMessage /> : null;
const spinner = loading ? <Spinner /> : null;
const content = !(loading || error || !comic) ? <View comic={comic}/> : null

return (
    <>  
        <AppBanner />
        {errorMessage}
        {spinner}
        {content}
    </>
)

And here is the View component, that render html, so I thinked, that I should add animation there, but it did't worked.

const View = ({comic}) => {
const {title, description, pageCount, price, thumbnail, language} = comic;
return (
    <CSSTransition timeout={300} classNames="comic">
        <div className="single-comic">
            <img src={thumbnail} alt={title} className="single-comic__img"/>
            <div className="single-comic__info">
                <h2 className="single-comic__name">{title}</h2>
                <p className="single-comic__descr">{description}</p>
                <p className="single-comic__descr">{pageCount}</p>
                <p className="single-comic__descr">{language}</p>
                <div className="single-comic__price">{price}</div>
            </div>
            <Link to="/comics" className="single-comic__back">Back to all</Link>
        </div>
    </CSSTransition>
)

CSS file:

.comic-enter{
   opacity: 0;
}
.comic-enter-active{
   opacity: 1;
   transition: opacity 300ms ease-in;
}
.comic-exit {                
   opacity: 1;
}
.comic-exit-active {
   opacity: 0;
   transition: opacity 300ms ease-in;
}

Thanks for helping

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda