salesforce / lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation
https://lwc.dev
Other
1.64k stars 393 forks source link

Add Context or Provide/Inject API to solve the Props Drilling problem #3861

Open AllanOricil opened 1 year ago

AllanOricil commented 1 year ago

Is your feature request related to a problem? Please describe.

I could not find a similar feature in lwc to solve the Props Drilling problem

Describe the solution you'd like

Maybe create something like Vue's Provide/Inject feature?

https://vuejs.org/guide/components/provide-inject.html

Describe alternatives you've considered

I would probably use this state management lib based redux

https://www.lwc-redux.com/

I'm not sure if this is the best solution because states are availble to any component in the tree, and not just the descendants of a component.

Additional context N/A

AllanOricil commented 1 year ago

After googling lwc prop drilling I could not find anything about it. It seems that it is not a problem lwc devs are aware of.

nolanlawson commented 1 year ago

Thanks for opening the issue! This pattern is also called context.

We have a few ways of doing this currently:

We have some ideas for improving this – e.g. see the "signals" RFC: https://github.com/salesforce/lwc-rfcs/pull/82

AllanOricil commented 1 year ago

Thanks for opening the issue! This pattern is also called context.

We have a few ways of doing this currently:

We have some ideas for improving this – e.g. see the "signals" RFC: https://github.com/salesforce/lwc-rfcs/pull/82

This signals feature is really nice. I hope you can release it soon. It reminds me of VHDL/Verilog signals where some part of my code would activate when a signal changed.

AllanOricil commented 1 year ago

@nolanlawson would there be a way to predict the order components react to a signal change? For example, if I have 100 components all subscribed to the same signal, which one of the components would react to the signal change first?

nolanlawson commented 1 year ago

@AllanOricil That's a great question. Could you raise it in the RFC as a clarification?

Off the top of my head, I would assume depth-first tree traversal order, but it would be great to have it clarified in the RFC.