-
Notifications
You must be signed in to change notification settings - Fork 53
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
Lazy loading example throws typescript error #78
Comments
why does animationdata need to be null? undefined is an accepted value too |
That would work too. Typescript just needs an initial value to not get angry |
if the typescript definition problem lies in react-lottie-player, then I'm happy to accept a PR to fix the definitions |
No need for a PR even. Just the example listed in the README needs 'undefined' or 'null' added to the useState. |
ah, but what I meant is that undefined should also be acceptable, so I don't think we should force users to use |
I guess since there are no const MyComponent = () => {
const [animationData, setAnimationData] = useState<any>();
useEffect(() => {
import('./animation.json').then(setAnimationData);
}, []);
if (!animationData) return <div>Loading...</div>;
return <Lottie animationData={animationData} />;
} |
Can you please post a screenshot of warning . |
Knowing that we are going to have JSON object as our state, it would probably be best to simply use const MyComponent = () => {
const [animationData, setAnimationData] = useState<object>();
useEffect(() => {
import('./animation.json').then(setAnimationData);
}, []);
if (!animationData) return <div>Loading...</div>;
return <Lottie animationData={animationData} />;
} |
Small thing, but typescript will throw an error on the following line:
const [animationData, setAnimationData] = useState();
simple solution is to add a null to the initial useState:
const [animationData, setAnimationData] = useState(null);
The text was updated successfully, but these errors were encountered: