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

[ui-core] add useSaveData hook for api calls #3864

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

ramprasadagarwal
Copy link
Collaborator

@ramprasadagarwal ramprasadagarwal commented Oct 14, 2024

What changes were proposed in this pull request?

  • Add useSaveData hook for react to save the data to the backend. This is similar to useLoadData hook implemented for fetching data.

How was this patch tested?

  • Added unit tests

Usage

const { loading: isSaving, save } = useSaveData(API_URL, {
  onSuccess: () => {
    setIsEditing(false);
  }
});

const handleSave = () =>
  save({
    path: fileData.path
  });

Copy link
Collaborator

@nidhibhatg nidhibhatg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

@bjornalm bjornalm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but see question.

setError(undefined);

try {
const PostUrl = localOptions?.urlPrefix ? `${localOptions.urlPrefix}${url}` : url;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't part of the reason for creating a save hook be to hide away details like url-prefix etc? Is there a use case for using this with different url-prefixes in Hue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I believe I have over complicated it. Let me remove the urlPrefix here and also in useLoadData

@ramprasadagarwal ramprasadagarwal enabled auto-merge (squash) October 16, 2024 08:04
@ramprasadagarwal ramprasadagarwal merged commit 59fad96 into master Oct 16, 2024
5 of 6 checks passed
@ramprasadagarwal ramprasadagarwal deleted the feat/add-use-save-data-hook branch October 16, 2024 08:08
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

Successfully merging this pull request may close these issues.

3 participants