Comments (6)
I would not call that 'simply' really :) Just showing that HOC is not always a good option :) Closing this now since you have no problem with keeping render prop variant exposed as well. Thanks.
from informed.
So i like HOC a lot more personally but i do still expose the Field component so u can still easilly use that. HOC makes creating custom inputs very easy and intuitive. I think in the end i will just expose both and let users pick what they want
from informed.
Oh, I should have probably looked into the code first :) I kinda assume that since it's not mentioned in the docs, it won't be there.
I don't like HOC mainly because of a clash of prop names. I want to pass some prop from the parent only to later find out it was overwritten by HOC to something else. Render prop components are much more transparent on this although nesting them is a rather hellish experience for sure :)
Btw, I also noticed some Scope component in examples, is that something similar to NestedField? It's undocumented too.
from informed.
Yeah so I actually like hoc for that reason lol because you dont have to explicitly pass props. And as for scope. Its similar but not the same. It allows u to scope fields and thay is it! It does not take validation functions and stuff
from informed.
I think I might have found the limitation of the HOC approach. Consider the following example with react-form. It's a self-contained input component that would validate value to be numeric. I don't want to always import validator separately and pass it into the component.
const FormInputNumeric = ({ field }) => (
<Field field={field} validate={validateNumber}>{fieldApi =>
<input onChange={...} value={fieldApi.value} />
}</Field>
)
How would you create such self-contained validated component with HOC? I don't believe it's possible directly. It would need to be another wrapping component around the HOC one. Or am I missing something here?
from informed.
Yeah in your case above. If i did not also export field comp. you could still achive this but it would not be clean. Simply wrap your component one more time with another component that sets the field and passes down the ...props
from informed.
Related Issues (20)
- Providing Form with new schema with updated property appears to have no effect in specific case. HOT 6
- validate one field based on another field value HOT 7
- Add React 18 peer dependency HOT 2
- onSubmit type definition HOT 2
- Parent state resetting when Child is unmounted HOT 3
- onChange, how to get access to all field event properties? HOT 5
- Support for SSR on useFormStateSelector HOT 2
- React has detected a change in the order of Hooks called by Root HOT 1
- Guidance needed for customizing Radio HOT 5
- Problem with custom Radio input HOT 3
- TypeScript - Examples of using unknown types? HOT 4
- Console log displayed when input has mask HOT 2
- onSubmit - setError is not a function HOT 1
- Missed some properties in FormApi type HOT 1
- `useField` does not return initial value on first render HOT 12
- TextArea - attribute HOT 3
- Q: Form with several buttons HOT 2
- File Input Field? HOT 1
- Zod support HOT 1
- onSubmit with Multi-Step? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from informed.