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

General React Component Help #66

Open
LTR14 opened this issue Jun 26, 2023 · 0 comments
Open

General React Component Help #66

LTR14 opened this issue Jun 26, 2023 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@LTR14
Copy link
Collaborator

LTR14 commented Jun 26, 2023

Source: (Any branch) PPUC/frontend/src/components/[any filename].jsx

Description: In React, it is sometimes crucial to share data between components. This is done throughout the codebase often currently and will most likely continue to happen to a greater extent as the site develops further. The current ACPP website is built using class-based components which changes the way a lot of things are done. "Lifting the state up" is an important technique in sharing data and it can be accomplished manually or in using the ContextAPI for class based components.

All components form a tree and within that tree there are several parents and one parent at the top of the tree that is a parent to all components. To share a variable from one component to another, you must pass this variable up the tree to at least the most recent shared ancestor. The state must be redefined here as well as functions that act on it and then passed down as props parameters to the components you want this state to be shared to that are children of the parent. This process is known as lifting the state and passing props down and is a common flow in React.

In the ACPP codebase, app.jsx is the root component from which all components are built from and is the place where you will lift states to if you want to share them to unrelated components. You can see this process already in Researchers.jsx to ResearcherResult.jsx and ResearcherResultSentence.jsx classes with the result variable in Researchers. This flow works because Researchers is the parent which creates the other two components.

Additional Notes/Resources: https://www.geeksforgeeks.org/lifting-state-up-in-reactjs/

https://legacy.reactjs.org/docs/context.html

@LTR14 LTR14 added the documentation Improvements or additions to documentation label Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant