--- title: State as a Snapshot --- State variables might look like regular JavaScript variables that you can read and write to. However, state behaves more like a snapshot. Setting it does not change the state variable you already have, but instead triggers a re-render. * How setting state triggers re-renders * When and how state updates * Why state does not update immediately after you set it * How event handlers access a "snapshot" of the state ## Setting state triggers renders {/*setting-state-triggers-renders*/} You might think of your user interface as changing directly in response to the user event like a click. In React, it works a little differently from this mental model. On the previous page, you saw that [setting state requests a re-render](/learn/render-and-commit#step-1-trigger-a-render) from React. This means that for an interface to react to the event, you need to *update the state*. In this example, when you press "send", `setIsSent(true)` tells React to re-render the UI: ```js import { useState } from 'react'; export default function Form() { const [isSent, setIsSent] = useState(false); const [message, setMessage] = useState('Hi!'); if (isSent) { return

Your message is on its way!

} return (
{ e.preventDefault(); setIsSent(true); sendMessage(message); }}>