score:0

it seems to me that the component is a bit too involved with the refresh mechanism, so i'd delegate that to a redux action instead:

// async download action
const downloadfile = (filename) => async (dispatch, getstate) => {
  await dispatch(refresh());
  const file = getstate().all.files[filename];
  file.download(); // it's not recommended to have functions in redux state btw
};

function downloadbutton(props) {
  const { selected, downloadfile } = props;

  return(
    <>
      {!!selected && <downloadbutton onclick={() => downloadfile(selected)} />}
    </>
  );
}

const mapdispatchtoprops = { downloadfile };

Related Query

More Query from same tag