--- title: OptimisticInput description: Creates a form input for optimistic UI updates. Use `useOptimisticData` to update the UI with the latest optimistic data. api_version: 2023-07 api_name: hydrogen source_url: html: https://shopify.dev/docs/api/hydrogen/2023-07/components/optimisticinput md: https://shopify.dev/docs/api/hydrogen/2023-07/components/optimisticinput.md --- # Optimistic​Inputcomponent Creates a form input for optimistic UI updates. Use `useOptimisticData` to update the UI with the latest optimistic data. ## Props * id string required A unique identifier for the optimistic input. Use the same identifier in `useOptimisticData` to retrieve the optimistic data from actions. * data Record\ required The data to be stored in the optimistic input. Use for creating an optimistic successful state of this form action. ### Examples * #### example ##### Description This is the default example ##### JavaScript ```js import {CartForm, OptimisticInput, useOptimisticData} from '@shopify/hydrogen'; export default function Cart({line}) { const optimisticId = line.id; const optimisticData = useOptimisticData(optimisticId); return (
); } ``` ##### TypeScript ```ts import {CartForm, OptimisticInput, useOptimisticData} from '@shopify/hydrogen'; import {CartLine} from '@shopify/hydrogen-react/storefront-api-types'; type OptimisticData = { action: string; }; export default function Cart({line}: {line: CartLine}) { const optimisticId = line.id; const optimisticData = useOptimisticData(optimisticId); return (
); } ```