Skip to content

[Feature Request] [hooks] input#value bindings with useState #156

@tomitheninja

Description

@tomitheninja

From facebook/react#18611 including dmytro-lymarenko's ideas

Summary

Many of the popular JavaScript frameworks support binding value to a HTMLInputElement

The purpose of value binding is to eliminate the need both the value and the onchange property.

I think, with the new useState syntax, it became possible to implement this in react with a nice syntax and no breaking changes.

Detailed design

function MyComponent() {
  const bind = useState('')
  const [value, setValue] = bind
  return (
    <input bind={bind} />
    // ...
  )
}

Alternatives

By introducing a new hook.
In my opinion, this is easier to learn.

const [value, bind] = useStateBind('')
<p>{value}</p>
<input bind={bind} />

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions