ExamplesButtonsMotion UI: Hold to confirm

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
Tutorial time
5 min
Difficulty

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