Search code examples
reactjsreact-spring

Animation duration in React Spring


I have a fairly simple fade-in scenario, where I want to control the duration of the animation. But cannot wrap around my head around how to accomplish this.

Code excerpt:

function BoxA() {
  return (
    <Spring from={{ opacity: 0.2 }} to={{ opacity: 1 }}>
      {props => (
        <div
          style={{
            height: 100,
            width: 100,
            backgroundColor: "pink",
            color: "#fff",
            ...props
          }}
        >
          1
        </div>
      )}
    </Spring>
  );
}

Complete code example: https://codesandbox.io/s/n7pw660264


Solution

  • You have to set the config property for the duration.

    <Spring config={{duration: 5000}} from={{ opacity: 0.2 }} to={{ opacity: 1 }}>