0

I try use React lazy and Suspense loading. I have simple login page and animation page for lazy loading. But if I refresh or open this page I cant see animation. But when write fallback = <p> Loading... </p> like this it is work. How to do I do this with animaition?
This is my main page for lazy loading:

import { lazy, Suspense } from "react";
import Login_Register from "../Loadingsss/login-register";
const Example = lazy(()=>import ('./Login'));
function Login(){
 return (
 <Suspense fallback={ Login_Register }>
 <Example />
 </Suspense>
 );
}
export default Login;

and this animation page:

import { useState } from 'react';
import {animated, useSpring} from 'react-spring';
function Login_Register(){
 const [toogle, setToggle] = useState(true);
 const props = useSpring({
 width: toogle===true ?'22rem':'0rem',
 backgroundColor: toogle ? '#ccc' : 'rgb(175, 175, 175)',
 height: '100%',
 borderRadius: '10px'
 });
 setInterval( ()=>{
 setToggle(!toogle);
 },1000 );
 
 return (<div className="loading">
 <div className="row">
 <animated.div style = {props.backgroundColor} className="circle"></animated.div>
 <animated.div style={props} className="rectangle"></animated.div>
 </div>
 <div className="row">
 <animated.div style = {props.backgroundColor} className="circle"></animated.div>
 <animated.div style={props} className="rectangle"></animated.div>
 </div>
 <div className="row">
 <animated.div style = {props.backgroundColor} className="circle"></animated.div>
 <animated.div style={props} className="rectangle"></animated.div>
 </div>
 <div className="row">
 <animated.div style = {props.backgroundColor} className="circle"></animated.div>
 <animated.div style={props} className="rectangle"></animated.div>
 </div>
 <div className="row">
 <animated.div style = {props.backgroundColor} className="circle"></animated.div>
 <animated.div style={props} className="rectangle"></animated.div>
 </div>
 
 
 </div>);
}
export default Login_Register;

How can I do this like upwork load animation?

asked Jun 5, 2021 at 11:47

1 Answer 1

0

You need to pass a React Element into fallback, not a Component. Surround Login_Register with < and /> to turn that Component into an Element. like this:

fallback={ <Login_Register /> }

answered Aug 19, 2021 at 18:32
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.