Comments (10)
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.
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.
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.
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.
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.
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.
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.
@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.
sooooo do you have it implemented yet? :)
from react-resolver.
+1
from react-resolver.
Related Issues (20)
- React.renderToStaticMarkup -> ReactDOMServer.renderToStaticMarkup HOT 2
- Can I use this without server rendering? HOT 3
- Add ability to cache resolved props HOT 9
- Using HOC breaks HMR
- Minimum universal react API HOT 1
- test
- Support variable? HOT 3
- Unhandled rejections server side HOT 1
- @context steals data from this.context HOT 6
- Allow factory to decide which props to re-use? HOT 5
- Documentation links are broken HOT 4
- Using same component on different routes HOT 3
- Using @client and @resolve on the same class causes @resolve to be called twice HOT 1
- Some way of manipulating data before passing it to component HOT 2
- Breakage with React 16: PropTypes no longer exported by React HOT 1
- "[email protected]" has incorrect peer dependency "react@^0.14.6 || ^15.0.0-0" HOT 5
- Need hydrate static method in the Resolver class for server side rendering HOT 2
- Fix compatibility with Babel 6
- Resolve multiple props with one callback HOT 5
- Initial Data from Django using React Resolver 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 react-resolver.