Skip to content

Instantly share code, notes, and snippets.

@herbowicz
Last active November 3, 2019 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herbowicz/23f72ae625ba7eb3419cc8fab545b3b3 to your computer and use it in GitHub Desktop.
Save herbowicz/23f72ae625ba7eb3419cc8fab545b3b3 to your computer and use it in GitHub Desktop.
Three dots animated . .. ... in loop
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;
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