Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pendingMeta to createAsyncThunk's thunkAPI #4313

Open
renchap opened this issue Mar 29, 2024 · 0 comments
Open

Add pendingMeta to createAsyncThunk's thunkAPI #4313

renchap opened this issue Mar 29, 2024 · 0 comments

Comments

@renchap
Copy link

renchap commented Mar 29, 2024

It is sometimes useful the have the same meta attributes in both the pending and fulfilled actions when using createAsyncThunk.

A solution to this could be to add the result of getPendingMeta to the thunkAPI argument, so the payload creator can use it without needing to recompute it again.

I looked at the source code and it seems easy to use a variable for the getPendingMeta result and add it to thunkAPI above.

Another solution would be to have a way to add a meta attribute to every action (and not only pending).

In our use-case, we are using a middleware to handle displaying a page-wide loading bar when some actions are loading remote data. It would be useful to be able to do something like this:

 getMeta: ({ arg: { id } }, { getState }) => ({
      showLoadingBar: true,
      locked: getState().accounts.get(id)?.locked || false,
    }),

The showLoadingBar would be used by the middleware, and the locked attribute is needed for both pending and fulfilled in the reducer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant