Giter Club home page Giter Club logo

Comments (6)

danielkcz avatar danielkcz commented on June 6, 2024 1

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.

joepuzzo avatar joepuzzo commented on June 6, 2024

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.

danielkcz avatar danielkcz commented on June 6, 2024

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.

joepuzzo avatar joepuzzo commented on June 6, 2024

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.

danielkcz avatar danielkcz commented on June 6, 2024

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.

joepuzzo avatar joepuzzo commented on June 6, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.