Skip to content
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

No animation when rendered with no children, then with some children #9

Open
ololoepepe opened this issue Sep 19, 2020 · 0 comments
Open

Comments

@ololoepepe
Copy link

ololoepepe commented Sep 19, 2020

The following example results in style="animation-duration: 0s;" even after some children are finally rendered.

import React, {useEffect, useState} from 'react';

const Component = () => {
  const [items, setItems] = useState([]);

  useEffect(() => {
    const timer = setTimeout(() => {
      setItems([{id: 1, text: 'abcde'}, {id: 2, text: 'fghij'}]);
    }, 1000);

    return () => clearTimeout(timer);
  }, []);

  return (
    <div style={{height: '50px'}}>
      <Marquee>
        {
          items.map(item => (
            <div key={item.id}>{item.text}</div>
          ))
        }
      </Marquee>
    </div>
  );
};

Workaround: add a key prop to the Marquee which reflects changes in items count.

Upd.: seems that we may just add children as a dependency here: https://github.com/mxmzb/react-marquee-slider/blob/master/src/Marquee.tsx#L97 This should also allow to automatically adjust animation speed if the content changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant