Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Input caret jumps to to the end when typing #270

Closed
timuric opened this issue Nov 5, 2021 · 1 comment
Closed

React Input caret jumps to to the end when typing #270

timuric opened this issue Nov 5, 2021 · 1 comment

Comments

@timuric
Copy link

timuric commented Nov 5, 2021

For some reason react input always jumps to the end of the field.
Try to type something, then change caret to anywhere else and type further.
Is Valtio doesn't work with controlled components or am I missing something?

import React from "react";
import { proxy, useSnapshot } from "valtio";

// create a base proxy
const state = proxy({
  text: ""
});

export default function App() {
  const { text } = useSnapshot(state);
  return (
    <input
      value={text}
      onChange={(e) => {
        state.text = e.target.value;
      }}
    />
  );
}

Live demo:
https://codesandbox.io/s/valtio-input-bug-el7l7

@dai-shi
Copy link
Member

dai-shi commented Nov 5, 2021

In short: const { text } = useSnapshot(state, { sync: true });

Maybe we can add a better note in readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants