Async Fetching Data w/ Props.params Query
See original GitHub issueSay you have a component that just displays a single TopicItem (…/containers/topicItem.jsx), and you want to async fetch the data for that item [using a URL-Query from props.params.topicID] similarly to how it’s done in Vote.jsx
:
static need = [ // eslint-disable-line
fetchTopics
]
How would you pass a query-ID to a similar “fetchTopic” to make the request like so?
export function fetchTopic(id) {
return {
type: types.GET_TOPIC,
promise: makeTopicRequest('get', id)
};
}
**Noticed that this same question has been asked a number of times and in several different places… Going to attempt to document a simple solution below, as none of the other discussions provide a clear cut answer as to how they “got it working.”
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Data Fetching: getServerSideProps
Learn how to fetch data on each request with Next.js. ... export async function getServerSideProps(context) { return { props: {}, // will be...
Read more >Async data made simple with React Query - Hey! I'm Tyler
The first parameter to useQuery is a string and this is how the hook knows what to cache when data is returned. You...
Read more >Common data fetching patterns for real apps with react-query
Fetch data and handle results: useQueries . Fetch a subset of data using query strings or query params: useQuery with parameters.
Read more >How to fetch with parameters using React Query?
So, in short: const getEvents(month) = async () => { const response = await axios.
Read more >Data Fetching – Fetching Data - Intro to Next.js
There are many ways to fetch data with Next.js. Depending on when you need the data and what you're doing with it, you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Take a look at this issue as well https://github.com/choonkending/react-webpack-node/issues/268 because they talk there on the same thing i believe 😃
We’re cleaning up issues on the project and since this is an old issue we’re closing it. Moreover, the code has changed quite a lot since this issue was opened. If you still experience this or have an issue, please comment here or open a new one