Skip to content

Refactor to adhere to React best practices #5630

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cipherlogs
Copy link

In this section, the words "fetched," "fetching," and "onFetched" are used frequently. so, including useSomeAPI() without any clarification in the example may cause confusion as it could be interpreted as a side effect. To clarify, it should be noted that useSomeAPI() is a side effect and should be wrapped in an useEffect() hook or an event handler to avoid potential issues.

To eliminate any confusion, either the wording used in the example can be modified, or it can be explicitly mentioned that useSomeAPI() should be wrapped in an useEffect() hook or an event handler. By doing so, it will ensure that the example follows React's best practices, which suggest that data should flow from parent components to their children, and updates to parent component state should not be made in child component effects.

Overall, making this clarification will improve the clarity of the example and prevent potential confusion for readers.

This commit refactors the data flow in the React codebase to follow best practices recommended by the React documentation. The changes ensure that data flows from the parent components to their children, and avoid updating the state of parent components in child component effects.

The Parent component is now responsible for fetching the data and passing it down to the Child component as a prop. The Child component no longer fetches the data or modifies the state of the Parent component, ensuring a predictable data flow and avoiding the introduction of side effects.

These changes improve the maintainability and scalability of the codebase, making it easier to debug and extend in the future.
@facebook-github-bot
Copy link
Collaborator

Hi @cipherlogs!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@github-actions
Copy link

github-actions bot commented Feb 25, 2023

Size Changes

📦 Next.js Bundle Analysis

This analysis was generated by the next.js bundle analysis action 🤖

This PR introduced no changes to the javascript bundle 🙌

@facebook-github-bot
Copy link
Collaborator

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants