Giter Site home page Giter Site logo

Comments (10)

ericclemmons avatar ericclemmons commented on August 14, 2024

Yea, the more I think about this, the more it doesn't seem to make sense to just pollute the base component with props.

from react-resolver.

iamdustan avatar iamdustan commented on August 14, 2024

From the consuming component, shouldn’t a given BaseComponent and BaseComponentContainer have the same interface?

I ran into this exact snag and that props weren’t passed through caught me off guard. Also, I didn’t realize I could pass them through so easily.

Could there be a declarative shorthand for passing props through on the resolve block?

resolve: {
  propKey: 'propKey', // automatically extract this
  '*': '*', // pass all props
  '...props': '...props',
  promise() { return fetch(...); },
}

from react-resolver.

ericclemmons avatar ericclemmons commented on August 14, 2024

Not necessarily. As an example, a project I have lets users request information from schools.

The base component has this interface: <RequestForm info={...} form={...} />.

But, lead and form are all from stores/actions and not the concern of the parent components.

Consumers use: <RequestForm school={school} />.

React Resolver takes care of gathering existing user-info for info and generating a form from the info.

I completely agree, though, that there's an overlap in props that should allow for a short-hand.

TBH, I think your propKey: "propKey" recommendation is the most explicit and simple. I initially thought "*" would work as well, but I'd really like to recommend against blind prop passing as I've personally had lost time with bugs that were passing foo preventing resolve: { foo: ... } from ever running.

(A good example of this is having a container convert IDs => Models, e.g. <School school="1" /> => <School school={{ id: 1, name: "Foo", ... }} />.

Thoughts?

from react-resolver.

iamdustan avatar iamdustan commented on August 14, 2024

Optionally, could the container automatically pass through declared propTypes?An incomplete idea:

class Base extends Component { render() { return <div /> }

Base.propTypes = {
  school: PropTypes.shape().isRequired,
  principal: PropTypes.string(),
};

export default Resolver.createContainer({ 
  resolve(props) {
    return Store.getSchool({id: props.id});
  }
});

<Base id={1234} />
<Base school={{name: 'Huff High', grades: '9-12'}} principal="Mr. Wilson" />

from react-resolver.

iamdustan avatar iamdustan commented on August 14, 2024

I guess part of my thinking is should a consuming component be aware of it’s child being automatically, asynchronously resolved or is that a private implementation detail?

from react-resolver.

ericclemmons avatar ericclemmons commented on August 14, 2024

Intersting! I don't see why the container can't be automatically aware, since it's meant to be smart.

I just ran into specific issues when names are more ambiguous (e.g. item) :)

from react-resolver.

iamdustan avatar iamdustan commented on August 14, 2024

Arg. I suspect I’ll need to pick this back up. I often just splat properties through for things like className or specific style properties for context and resolver is eating all of that for me at the moment.

from react-resolver.

ericclemmons avatar ericclemmons commented on August 14, 2024

@iamdustan Actually, in recent projects I've found that it makes since for HoCs to compose props onto the base Component.

In other words:

  • Props should propagate :)

from react-resolver.

iamdustan avatar iamdustan commented on August 14, 2024

sooooo do you have it implemented yet? :)

from react-resolver.

AlesJiranek avatar AlesJiranek commented on August 14, 2024

+1

from react-resolver.

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.