Giter VIP home page Giter VIP logo

Comments (5)

emplums avatar emplums commented on September 2, 2024 1

Oh that is super cool! Totally forgot we could use react context for this 🤔 Since this would be a bit of a refactor, I'll make an issue for it for safe keeping!

from blueprints.

shawnbot avatar shawnbot commented on September 2, 2024

Yay, happy to see this happening! Please don't feel like you have to keep any of these component names... NodeLink might have made sense for me, but it may not for anyone else. 😂 Maybe we call them PageLink, etc.?

Also, I think I may have discovered a better way to get the list of pages in Next.js, which should eliminate all of the pages hackiness that's happening.

from blueprints.

emplums avatar emplums commented on September 2, 2024

Oooh I would be very interested in hearing more!

from blueprints.

shawnbot avatar shawnbot commented on September 2, 2024

After hunting around GitHub and Spectrum, I found this thread which suggests that contexts can share data between server and client. If that's the case, then I think it looks something like this:

// pages/_document.js
import NextDocument from 'next/document'
import Pages from '../docs/pages'

export default Document extends NextDocument {
  render() {
    const {buildManifest} = this.props
    return (
      <Pages.Provider value={buildManifest.pages}>
        ...
      </Pages.Provider>
    )
}
// docs/components/SideNav.js
import Pages from '../docs/pages'

export default props => (
  <Pages.Consumer>
    {pages => (
      // do something with the pages object
    )}
  </Pages.Consumer> 
)

...and I guess only the components that need access to it would use <Pages.Consumer>?

If contexts don't work across the server/client boundary, then we might need to wire up a slightly hackier solution, but it's got to be better than what we have now. 😬

from blueprints.

shawnbot avatar shawnbot commented on September 2, 2024

Maybe an HOC that wraps withRouter() would be nice:

export function withPages(Component) {
  return withRouter(props => (
    <Pages.Consumer>{value => <Component pages={value} {...props} />}</Pages.Consumer>
  ))
}

from blueprints.

Related Issues (18)

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.