docs icon indicating copy to clipboard operation
docs copied to clipboard

`provide`/`inject` cascading nature documentation

Open padcom opened this issue 2 years ago • 0 comments

What problem does this feature solve?

When using provide multiple times in the component tree, the closes parent provides the value injected with inject. This means that if we have let's say a Menu component that provides some data and functionality and then in one of the MenuItems that uses this functionality we'll provide them again using the same injection key two things will happen:

  • the child components will get the value provided by 2nd-level Menu
  • for other components outside of that tree, the value will still be from the closes parent, so won't be overriden

This behavior is great for composing component tree from individual components that need to know about themselves. In the docs there's just the statement:

Providing reactive values allows the descendant components using the provided value to establish a reactive connection to the provider component.

I think it'd be great if the scoping nature of provide would be better explained, maybe with an example.

This is a purely documentation issue - everything works as expected code-wise.

What does the proposed API look like?

No changes

padcom avatar Jun 22 '23 08:06 padcom