Can this partial application, action creator be rewritten using Object.Assign or the spread operator?

Viewed 17

Can this be rewritten using Object.Assign or the spread operator?

This is an action creator for a redux call using closures. I believe this syntax can be improved.

const create = (actionName) => {
  const type = `${actionName}`;
  const func = ({ status, id = cuid() }) => ({
    type,
    payload: {
      [id]: { status },
    },
  });
  func.type = type;
  return func;
};

Usage

const addQuestion = createQuestion("add");
const updateQuestion = createQuestion("update");
0 Answers
Related