Last active
November 3, 2019 10:17
-
-
Save herbowicz/23f72ae625ba7eb3419cc8fab545b3b3 to your computer and use it in GitHub Desktop.
Three dots animated . .. ... in loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import styled from "styled-components"; | |
import ThreeDots from "../components/ThreeDots"; | |
const Loading = styled.p` | |
color: #666; | |
display: table-cell; | |
vertical-align: middle; | |
`; | |
const Loading = props => { | |
return ( | |
<> | |
{props.data ? ( | |
<> | |
{* / / *} | |
</> | |
) : ( | |
<Loading> | |
Loading | |
<ThreeDots /> | |
</Loading> | |
)} | |
</> | |
); | |
}; | |
export default Loading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from "react"; | |
const ThreeDots = () => { | |
const [dots, setDots] = useState("."); | |
useEffect(() => { | |
const interval = setInterval(() => { | |
setDots(dots.length > 2 ? "" : dots + "."); | |
}, 400); | |
return () => clearInterval(interval); | |
}, [dots]); | |
return <span>{dots}</span>; | |
}; | |
export default ThreeDots; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment