-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Moving builder and condition into a "use" hook (maybe useBlocBuilder) for react-bloc #39
Comments
Hi @theweiweiway 👋 I agree that your proposal is more "react-like" and would be a lot more familiar to the existing react community while still preserving the core concepts/behavior of the bloc library. Unfortunately, I'm focusing on migrating the dart bloc ecosystem to null safety right now but if you're willing to give this a shot, I'm always happy to review the code 👍 If you're busy/prefer not to work on the implementation, no worries! I'll try to get to this in the coming weeks 😄 |
Hey Felix, This might be over my head, but I'll look through the code and try to give it a shot! |
No worries at all! If you have any questions don't hesitate to ask and again if you prefer to wait that's totally fine as well 👍 |
Hey @felangel, I've got something that kind of looks like a Here's your
OK - Thanks Felix! |
Closing due to PR #40 |
Hi Felix!
Thanks for your port of the bloc library to React! I have a feature suggestion due to the limitations I'm facing with
<BlocBuilder ... />
Is your feature request related to a problem? Please describe.
<BlocBuilder .../>
is great, but it has some limitations:<BlocBuilder bloc={<how_do_i_easily_get_this_bloc>} ... />
in the tree must be prop-drilled down, OR passed viauseContext
. The problem withuseContext
is that it doesn't update when bloc state changes (not sure why it behaves like this). For example:this does not trigger the console.log to show the new state. However, if I use a
<BlocBuilder bloc={<bloc_from_useContext>}/>
component and pass the authBloc in from the useContext, I get the most updated state. But using authBloc.state directly from the context won't give me the newest state. This has implications, for example:useEffect
hook (in Flutter, we can just use context to access the most updated version of the Bloc in initState)<BlocBuilder .../>
is that we are relying on a renderProp to use the state which is not a huge problem, but it is undesirableDescribe the solution you'd like
If we had a
useBlocBuilder
hook instead of a<BlocBuilder ... />
component like so:On top of this, we could also have a
useBlocListener
hookNot only is this much more react-ish, it's more concise and easier to use (in my opinion). AND, it still preserves the "spirit" of bloc library by using BlocBuilders, having conditions, etc.
The text was updated successfully, but these errors were encountered: