Skip to content

refactor: extract state to contexts to reduce prop drilling#800

Open
lucaengelhard wants to merge 22 commits intoCyberTimon:mainfrom
lucaengelhard:refactor/extract-state-to-contexts
Open

refactor: extract state to contexts to reduce prop drilling#800
lucaengelhard wants to merge 22 commits intoCyberTimon:mainfrom
lucaengelhard:refactor/extract-state-to-contexts

Conversation

@lucaengelhard
Copy link

@lucaengelhard lucaengelhard commented Mar 4, 2026

Description

Currently the App.tsx file of the frontend is very cluttered and instantiates a lot of useStates, useEffects and functions that are used globally, but mainly within subcomponents. This PR extracts all of them out into contexts and hooks so that they can be used globally without having to pass them as args.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Performance improvement
  • Code refactoring
  • Documentation update
  • UI/UX improvement
  • Build/CI or Dependency update

Changes Made

  • Extracted the State declarations made in the App.tsx file to a context object
  • Added helper function for creating new global state
  • Extracted global Effects and methods into hooks

Screenshots/Videos

Testing

  • I have tested these changes locally and confirmed that they work as expected without issues

Test Configuration:

  • OS: Omarchy 3.4.1 (Linux 6.18.13-arch1-1)
  • Hardware: NVIDIA RTX 4060, Intel i5-11400F

Checklist

  • My code follows the project's code style
  • I haven't added unnecessary AI-generated code comments
  • My changes generate no new warnings or errors

Additional Notes

AI Disclaimer:

Please state the involvement of AI in this PR:

  • This PR is entirely AI-generated
  • This PR is AI-generated but guided by a human
  • This PR was handwritten with AI assistance (spell check, logic suggestions, error resolving)
  • This PR contains only blood, sweat, and coffee (AI-free)

@lucaengelhard lucaengelhard marked this pull request as ready for review March 5, 2026 19:00
@lucaengelhard
Copy link
Author

lucaengelhard commented Mar 5, 2026

@CyberTimon does this fit what you imagined for reducing prop drilling? the handlers can now also largely be removed from the App.tsx component. And maybe then the components themselves could also be extracted so that the main component isn't that long.

Maybe for a first step the extracted contexts and methods can be merged and the modified components come later. that way the different functions can be refactored step by step

@lucaengelhard
Copy link
Author

@CyberTimon no stress, but what is your usual timeframe and routine for reviews and feedback? so that i know how long to wait :) I would love to contribute more!

@CyberTimon
Copy link
Owner

Hey @lucaengelhard, thanks for the contribution and sorry for the delayed response! I appreciate the effort you've put into this.

I'm in a bit of a tough spot with this one. The reason I can develop this project as fast as I do is because I heavily rely on language models during development. These models need access to most of the code at once to understand the relationships and context between different parts of the application.

Splitting almost every function into its own separate file would actually kill a lot of my development speed and make the project much harder for me to maintain going forward. The current structure, even if it's "cluttered" by traditional standards, works well with how I build and iterate on this codebase.

But I definitely do see the value in reducing prop drilling (that's why I also put it in the readme todo section) and I'm not against improvements in that direction. I just need to find a balance that doesn't fragment the codebase into 80+ changed files where context is spread across dozens of small files.

Could we maybe find a middle ground? For example, extracting just a few key contexts without going as far as splitting every piece of state and every hook into its own file? Something that cleans things up a bit but keeps enough code co-located that the overall structure remains easy to work with?

Thanks so much!!
Timon

@lucaengelhard
Copy link
Author

Hey @CyberTimon yeah I understand that llms need all the context and thats easier to access in a single file. But at some point I think it will get super unmaintainable and its already hard to get into developing and contributing because its super unclear which part of the code affects what and what state depends on what.

So maybe this is a more foundational question than just prop drilling, because I think a general refactor that makes a lot of components more generic and makes the control and information flow clearer would be really beneficial for accessibility for other contributors and probably also for yourself in the future. Idk what the right answer is tbh, because I'm not that into language models so I can't give you an answer on what would be best for that workflow, but I think that overreliance on them could hurt the project in the long run as it gets way to cluttered to maintain

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