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

Create context for global app state #65

Open
MargotRasamy opened this issue Feb 6, 2023 · 1 comment · May be fixed by #66
Open

Create context for global app state #65

MargotRasamy opened this issue Feb 6, 2023 · 1 comment · May be fixed by #66

Comments

@MargotRasamy
Copy link

Suggestion :

As the app is starting to grow and we are welcoming new features, I suggest to add React's Context to handle global data to avoid using props on multiple hierarchy levels. We could also by the same occasion export the getFeed method to another file so all component have access to it. This way, we would avoid passing getFeed as props to every component.

In order to achieve this, we need to :

  • Create the context
  • Use an initial state with these data : the user's currently displayed feed , the user's previous feeds, the user's favorite feeds, the fetching state of the feed, and the error indicator. We suggest this format for the initial state :
const initialState = {
  currentFeed: {
    episodes: [],
    program_title: '',
    program_image: '',
    program_description: '',
    program_link: ''
  },
  onFetching: false,
  previousFeeds: [],
  error: false,
  favoriteFeeds: [],
};
  • Create the corresponding reducers to update the state (add, remove)
  • Export the getFeed method to another file to avoid sharing the method via props on too many hierarchy levels
@MargotRasamy MargotRasamy linked a pull request Feb 6, 2023 that will close this issue
@Tusharjagi
Copy link

Instead of using Context introducing a state management library will help in the future .

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 a pull request may close this issue.

2 participants