question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best pattern to fetch data based on a path

See original GitHub issue

Expected behavior

var html = require('choo/html')
var choo = require('choo')

var app = choo()
app.use(productStore)
app.route('/product/:id', mainView)
app.mount('body')

function mainView (state, emit) {

  return html`  <body onload=${pullData}>
      <h1>product is ${state.product.name}</h1>
    </body>
  `
  function pullData(){
    emitter.emit('fetchProduct');
  }
}

function productStore (state, emitter) {
  emitter.on('fetchProduct', function () {
    fetch('/product/'+state.params.id,function (product) {
       state.product = product;
       emitter.emit('render')
    })
  })
}

I was wondering if this is a good pattern in order to fetch some data when access some URL.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
intellecatcommented, Nov 29, 2017

This is a very common issue ! Do you really use Choo in your real project ? @yoshuawuyts Forgive my rudeness, but the routing system in Choo really sucks ! I’m very rude, and the routing system in Choo really sucks !

3reactions
josephluckcommented, Nov 28, 2017

@chuck911 - You’re being very hurtful by saying an open source library that has taken 100s of hours of people’s free time sucks. What’s more is you haven’t suggested anything constructive that solves the issue at hand.

Please take a moment before posting comments that purposefully upset people who are passionate contributors to open source.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Which design pattern suitable to fetch same type of data from ...
Which design pattern suitable to fetch same type of data from multiple sources, club them into a single unit and applying multiple filters....
Read more >
A comprehensive guide to data fetching in React
We explore common data fetching strategies in React, paired with examples and alternatives. See which approach is best for your next ...
Read more >
Common big data design patterns | Packt Hub
This article covers big data design patterns based on various data layers such as data sources and ingestion layer, data storage layer etc....
Read more >
NextJS / React SSR: 21 Universal Data Fetching Patterns ...
21 Universal Data Fetching Patterns & Best Practices for NextJS / React SSR.
Read more >
When to Use Different Data-Fetching Methods in Next.js
One of the reasons why Next.js has become such a popular framework for building React-based websites is that it provides so many different ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found