Quantcast
Viewing latest article 40
Browse Latest Browse All 43

Answer by Chamilyan for How to create a simple spinning animation for an image in React

Control spin speed by setting an initial property then propagate it to a react hook to be dynamically changed.

const SPEED = 0;const kind  = React.createElement,container = "react-container";const tags  = {    cat     : document.querySelector('[data-cat]'),    burger  : document.querySelector('[data-burger]')}class Main extends React.Component {    constructor(props){        super(props)    }    componentDidMount() {        alert("say cheeze!")    }    render() {        const kinds = [];        Object.keys(tags).map(function(key, index) {            const targets = {                 key : index,                 tag : tags[key].tagName.toLowerCase(),                 src : tags[key].src,                 SPEED            }            kinds.push(kind(Spin, targets))        });        return kinds    }}const Spin = function(props) {    const [speed, go] = React.useState(props.SPEED);        const startSpin = function() {        go(speed + 1)    };    React.useEffect(function() {        startSpin()    }, []);    return kind(props.tag, { style : { animation : `spin ${speed}s linear infinite` }, src : props.src })}

Demo https://gif.com.ai?id=QmagKQ16ZhwPMGunhWuiKydEJFW3y4MprxYeTNjbC87MxZ

From: https://dev.to/egfx/thinking-in-gif-with-react-5am0


Viewing latest article 40
Browse Latest Browse All 43

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>