79688233

Date: 2025-07-03 01:55:08
Score: 1
Natty:
Report link

What I found gave me the desired effect was porting my basic operations to RTK Query.

From a thunk, when RTK query actions are dispatched, they can be awaited and there result is returned. For example:

export const createAndNameThing = createAsyncThunk(
  'things/createAndName',
  async (name: string, { dispatch }) => {
    // Step 1: Create the thing
    const createResult = await dispatch(
      thingApi.endpoints.createThing.initiate(undefined)
    ).unwrap();

    // Step 2: Update the thing with the name
    const updateResult = await dispatch(
      thingApi.endpoints.updateThing.initiate({
        id: createResult.id,
        data: name
      })
    ).unwrap();

    return updateResult;
  }
);
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Starts with a question (0.5): What I
  • Low reputation (1):
Posted by: micahg