Motion+

Hold to confirm

A Motion for React example showing long-press interaction. The button's events update a progress motion value that drives multiple animations of other motion values.

React
Tutorial time
5 min
Difficulty

Tutorial

Introduction

The Hold to Confirm example shows how to create a button that visually responds to a long press, before confirming an action.

In this tutorial, we'll learn how to use:

Get started

Let's start with the basic structure of our component:

"use client"

import { animate, motion, useMotionValue, useTransform } from "motion/react"

export default function HoldToConfirm() {
    return (
        <div style={styles.container}>
            <div style={styles.buttonWrapper}>
                <button style={styles.button}>
                    <div style={styles.buttonBackground} />
                    Hold to confirm
                </button>
            </div>
        </div>
    )
}

/** Copy styles from example source */

This gives us a simple button with some basic styling, but it doesn't have any interactive behavior yet.

Related examples

Latest in React

Motion+

Unlock all 400+ examples

  • Source code for every Plus example.
  • Provide examples direct to your agent via Motion's MCP.
  • Lifetime access to new examples and APIs.