Using CSS transform: translate(...) with ReactJS

Guy Laor picture Guy Laor · Sep 17, 2015 · Viewed 57.2k times · Source

According to https://facebook.github.io/react/tips/inline-styles.html

CSS styles need to be passes as an object to the component. However, if you are trying to use transform styles you will get an error.

Answer

MarvinVK picture MarvinVK · Nov 4, 2016

Translate also wasn't working for me. I fixed it by adding 'px' behind the var.

ES6 code:

render() {
    const x = 100;
    const y = 100;
    const styles = { 
        transform: `translate(${x}px, ${y}px)` 
    };

    return (
        <div style={styles}></div>
    );
}