You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Valtio state with controlled `<input>` elements, you might notice the text caret jumping to the end while typing in the middle of the existing text.
156
+
157
+
This happens because Valtio batches state updates causing React to re-render after the input event. React resets the DOM value and loses the caret position.
158
+
159
+
**Use `{ sync: true }` to update synchronously and preserve the caret:**
160
+
161
+
```jsx
162
+
functionInput() {
163
+
constsnap=useSnapshot(state, { sync:true })
164
+
165
+
return (
166
+
<input
167
+
value={snap.text}
168
+
onChange={(e) => {
169
+
state.text=e.target.value
170
+
}}
171
+
/>
172
+
)
173
+
}
174
+
```
175
+
176
+
`sync: true` disables batching so React re-renders within the same event loop tick, skipping the DOM update and preserving the caret position.
177
+
151
178
## Issue with `array``proxy`
152
179
153
180
The following use case can occur unexpected results on `arr` subscription:
0 commit comments