Giter Site home page Giter Site logo

Defaults? about next-apollo HOT 2 OPEN

adamsoffer avatar adamsoffer commented on June 24, 2024
Defaults?

from next-apollo.

Comments (2)

sbking avatar sbking commented on June 24, 2024

@ads1018 I agree with including defaults, so the user can just wrap their component in the HOC without adding anything else special.

This new version of the package changes the approach so that rather than creating a confusing factory function, you add some combination of static methods on your component (getInitialProps, getApolloClient, and getReduxStore). Obviously these can and should be turned into a super component or a HOC by the user so they can be shared on multiple pages. See https://github.com/sbking/next-apollo-example/blob/using-npm-package/pages/index.js

The getInitialProps and getReduxStore static methods are optional as of now. It would be easy to make the getApolloStore method optional as well, perhaps by using an apolloUri prop or something on the component.

When I first started working on this, I found that I was trying to extract out every little configuration you can make into settings passed to the HOC. I'm all for creating some reasonable defaults for getting started with minimal configuration, but I think the approach should generally encourage the user to use the native APIs for production code, in which they should be writing essentially the same apollo / redux code that they would be writing in any other framework, while this package handles the stuff that is specific to next.js.

from next-apollo.

adamsoffer avatar adamsoffer commented on June 24, 2024

This new version of the package changes the approach so that rather than creating a confusing factory function, you add some combination of static methods on your component (getInitialProps, getApolloClient, and getReduxStore). Obviously these can and should be turned into a super component or a HOC by the user so they can be shared on multiple pages. See https://github.com/sbking/next-apollo-example/blob/using-npm-package/pages/index.js

I'm not sure I completely follow. In your example, it seems you would have to include those static methods on every page you want to fetch data. As well as the configuration files initClient and initStore. Is that correct? Or are you saying that example file should be a HOC that lives inside a user's lib directory?

I'm all for creating some reasonable defaults for getting started with minimal configuration, but I think the approach should generally encourage the user to use the native APIs for production code, in which they should be writing essentially the same apollo / redux code that they would be writing in any other framework, while this package handles the stuff that is specific to next.js.

Agreed.

from next-apollo.

Related Issues (3)

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.