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

Possible problem in Input Component #754

Open
Danielecina opened this issue Dec 10, 2024 · 0 comments
Open

Possible problem in Input Component #754

Danielecina opened this issue Dec 10, 2024 · 0 comments
Labels
bug Something isn't working Input component Input component and hooks related activities

Comments

@Danielecina
Copy link
Member

Danielecina commented Dec 10, 2024

The feature or bug you are proposing

Input

The description of the bug or the rationale of your proposal's

wrong update of the state according to the react docs guide -> https://react.dev/reference/react/useState#updating-state-based-on-the-previous-Ifate

A snippet of code for replicating the issue or showing the proposal usage if applicable

const [val, setVal] = useState()
const handleChange = useCallback((event: ChangeEvent<HTMLInputElement>) => {
    const { value: nextValue } = event.target
    const nextVal = { ...val, [valuePropName]: nextValue }
    setVal(nextVal)
    if (onChange) {
      onChange(event, addonBeforeProp || addonAfterProp ? nextVal : nextValue)
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
 }, [addonAfterProp, addonBeforeProp, onChange, valuePropName])

The expected result for your bug

setVal(curentObj => {
  const nextVal = { ...curentObj, [valuePropName]: nextValue }
  if (onChange) {
    onChange(event, addonBeforeProp || addonAfterProp ? nextVal : nextValue)
  }
})

Your environment

browser: not important
node: 22
os: Mac

@Danielecina Danielecina added bug Something isn't working Input component Input component and hooks related activities labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Input component Input component and hooks related activities
Projects
None yet
Development

No branches or pull requests

1 participant