-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only exporting withFeatures restricts use cases. #98
Comments
So |
Yes, I think we can just use props to provide That means that the enabled features will be more dynamic and will require a change to what the |
If we want to make a quicker intermediate change, we could configure the import React, { Component } from 'react';
import { features } from '@paralleldrive/react-feature-toggles';
const initialFeatures = [
{ name: 'foo', enabled: false },
{ name: 'bar', enabled: true },
];
const Features = createFeatures({initialFeatures});
const withFeatures = WrappedComponent => {
class WithFeatures extends Component {
static async getInitialProps(ctx) {
const { req, query } = ctx;
const subProps = await loadGetInitialProps(WrappedComponent, ctx);
return {
...subProps,
query
};
}
render () {
const query = this.props.query || this.context.query;
return (
<Features query={query}>
<WrappedComponent {...this.props} />
</Features>
);
}
}
);
export default withFeatures; |
What if it was a render prop component? Would that add any useful flexibility? For one thing, we could easily reimplement a default const withFeatures = Component => (
<Features initialFeatures={initialFeatures} query={query}>
{props => <Component {...props} />}
</Features>
); Maybe all our OSS HOCs should be written this way, so we can provide both flexible reuse (render prop) and easy root level function composition (HOC). |
Yeah that works too and is a bit more flexible! I like it |
BTW, don't worry about breaking changes. Break away if it gives us a better API. Breaking things early is better than breaking things later. =) |
great! I will get started then |
Is this solved now? |
No, the pr was only for the render prop component. Now that its merged I can continue |
👍 sorry for the delay. This fell of my radar. Feel free to ping if I block you on things! :) |
Closing as this component will be replaced by the component in #102 |
WIP
Issue
Some projects using nextjs use
loadGetInitialProps
so that they can usegetInitialProps
in inner components. We currently only exportwithFeatures
hoc. We can't add this functionality towithFeatures
without making nextjs a dependency.Applications can't make their own
withFeatures
hoc because we don't export a normal react component that they can build from.Solution
Stuff will be here soon.
Dream Code
Some examples of the new code.
Creating a root component
Creating a HOC in some application that needs a custom hoc
The text was updated successfully, but these errors were encountered: