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

Bug: Context Provider not re-rendering when adding multiple arguments to a custom hook #29054

Open
Slyracoon23 opened this issue May 14, 2024 · 0 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@Slyracoon23
Copy link

Slyracoon23 commented May 14, 2024

React version: ^18.2.0

Steps To Reproduce

  1. Create a custom hook that accepts a single argument and fetches data based on that argument.
  2. Use the custom hook in a Context Provider component and verify that the provider re-renders when the data updates.
  3. Modify the custom hook to accept multiple arguments (e.g., two arguments).
  4. Use the modified custom hook in the Context Provider component with multiple arguments.
  5. Update the data related to the arguments and observe if the Context Provider re-renders correctly.

Link to code example: https://gist.github.com/Slyracoon23/b1b3f5225ad56e2a84d00e2efd2b3c64
Loom video: https://www.loom.com/share/1239ea003063459d9687a9804f998c5b

The current behavior

  • When using a single argument in the custom hook, the Context Provider re-renders correctly when the data updates.
  • However, when using multiple arguments in the custom hook, the Context Provider does not re-render properly when the data updates.

The expected behavior

  • The Context Provider should re-render correctly whenever the data fetched by the custom hook updates, regardless of the number of arguments passed to the hook.

Additional Information

  • The issue seems to be related to how React handles re-rendering when multiple arguments are passed to a custom hook used within a Context Provider.
  • The problem is not specific to any particular data fetching library or API, but rather a general React behavior.

Possible Causes

  • React may not be correctly detecting changes in the custom hook's dependencies when multiple arguments are used.
  • The way the custom hook is implemented or used within the Context Provider might be causing the re-rendering issue.

Suggested Solutions

  • Investigate how React handles re-rendering when multiple arguments are passed to a custom hook.
  • Review the implementation of the custom hook and ensure it correctly handles multiple arguments and updates the data accordingly.
  • Verify that the Context Provider is correctly consuming the data from the custom hook and re-rendering when changes occur.

Additional Context

  • The relevant code snippets for the Context Provider and custom hook are provided below:
// ContextProvider.tsx
// ...

const { data, error, loading } = useCustomHook(arg1, arg2)

// ...
// useCustomHook.tsx
// ...

export const useCustomHook = (arg1: string, arg2: string) => {
  // ...
}

// ...
@Slyracoon23 Slyracoon23 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label May 14, 2024
@Slyracoon23 Slyracoon23 changed the title Bug: Thread details not updating correctly in Context Provider Bug: Context Provider not re-rendering when adding multiple arguments to a custom hook May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

1 participant