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.

Fetch data by Redux from browser

See original GitHub issue

Good day! How can I use fetch in Redux action? I use fetch from context in React component like this:

        static contextTypes = {
		fetch: PropTypes.func.isRequired,
	};
        ...
        async getData {
		const URL = '/api/search/content';
		const res = await this.context.fetch(URL);
		const {data} = await res.json();
                 ...
	}
       ...
      <button onClick={this.getData.bind(this)}/>

And now I want to do fetch in Redux action, and my question is how can I use this.context.fetch in Redux action

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

4reactions
Jaikantcommented, Mar 1, 2018

I also missed pointing out the other error I was making. The return async takes in 3 parameters, the third parameter contains the fetch function. Like below.

export function xyz() { // redux action
  return async (dispatch, getState, { fetch, graphqlRequest }) => {
0reactions
langpavelcommented, Mar 9, 2018

There is fetch helper injected to redux-thunk actions

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redux Essentials, Part 5: Async Logic and Data Fetching
The official Redux Essentials tutorial: learn how async logic works in Redux apps.
Read more >
Data fetching with Redux and Axios - LogRocket Blog
Learn how to use Redux and a library like Axios to turn data fetching and state management from a nightmare to a breeze....
Read more >
Redux Toolkit Tutorial - 30 - Fetching Data - YouTube
Your browser can't play this video. ... Business - codevolution.business@gmail.com Fetching Data with React and Redux Redux Toolkit Tutorial ...
Read more >
Fetching data in Redux using RTK Query - OpenReplay Blog
Along with using Redux for state management, you can now also fetch and cached data with ease without using React Query, SWR, ...
Read more >
Data fetching in Redux is painful, get rid of it now - Medium
Fetching data in Redux is a quite verbose process. Each fetch operation requires the developer to create: ... Writing all this code takes...
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