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
{{ message }}
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.
The form wrapping feels a bit weird, requires a lot of context of the inner workings of Form and its state. The result is that it'll tie your app in pretty hard, or at a minimum require you to maintain a middle-tier abstraction for it. I don't have a working implementation yet (but I'm hacking something together) but I was thinking of an API like this:
// Expect my component to have a single input, and name itconstCustomInput=({label, name, type})=><fieldset><labelhtmlFor={name}>{label}</label><inputname={name}type={type}/></fieldset>;constUsername=field('username')(CustomInput);classAppextendsComponent{submit(...args){returnnewPromise(ok=>ok(console.log(args)));}render(){return(<divclassName="App"><FormonSubmit={this.submit}><Usernamelabel="email"name="username"type="text"/><FieldWraplabel="Password"name="password"type="password"/><buttontype="submit">Submit</button></Form></div>);}}
Then the field HOC is the only thing that knows about the context or the inner workings. It could still pass along the specialized callbacks as props, in case they want to tie those into the component but its super easy to never know about it if you don't care.
The actual implementation would have to include walking the tree to find the input(s) which is the downside, but then you assure that the attaching happens correctly and can handle common scenarios the user might not think about like the onChange they provide should probably also be executed in addition to the attached one.
The text was updated successfully, but these errors were encountered:
The form wrapping feels a bit weird, requires a lot of context of the inner workings of Form and its state. The result is that it'll tie your app in pretty hard, or at a minimum require you to maintain a middle-tier abstraction for it. I don't have a working implementation yet (but I'm hacking something together) but I was thinking of an API like this:
Then the
field
HOC is the only thing that knows about the context or the inner workings. It could still pass along the specialized callbacks as props, in case they want to tie those into the component but its super easy to never know about it if you don't care.The actual implementation would have to include walking the tree to find the input(s) which is the downside, but then you assure that the attaching happens correctly and can handle common scenarios the user might not think about like the
onChange
they provide should probably also be executed in addition to the attached one.The text was updated successfully, but these errors were encountered: