question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to pass an EventCallback as a CascadingValue without using internal framework use methods?

See original GitHub issue

Issue description

Some methods are described with “For internal framework use only.”

I have been using EventCallback.Factory.Create(Object, EventCallback) to pass an EventCallback as a CascadingValue. This allows me to pass the EventCallback down a few levels without having to pass it explicitly through each razor component between the one with the callback function and the one that will call it.

I recently saw in the documentation it is described by the following:

Returns the provided callback. For internal framework use only.

I assume this means it should not be used or that it can disappear from a future release (with or without notice).

I’ve tried using the other Create methods in EventCallback.Factory/EventCallbackFactory, but haven’t been able to accomplish the same thing without compile errors.

cc: @guardrex

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
blowdartcommented, Aug 13, 2020

Ok that I can’t comment on. Let me edit the title so it’s better and someone might pick it up.

But you might want to describe what you’re trying to do, rather than say “I want this”. For example “Why do you want a cascading value event callback?”, what are you trying to achieve?

0reactions
mrlifecommented, Oct 16, 2020

@SteveSandersonMS Thank you very much! I got it working with a slight alteration to the second line (due to MyMethod taking a parameter of type MyClass):

var callback = new EventCallback<MyClass>(this, (Action<MyClass>)MyMethod);

I have another one that has a method that returns Task and takes no parameters, so I used the following for that one. Putting this here for anyone else who might be unsure about how to handle this case.

var callback = new EventCallback(this, (Func<Task>)MyMethod);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Cascading Values & Cascading Parameters
Cascading values and parameters are a way to pass a value from a component to all of its descendants without having to use...
Read more >
ASP.NET Core Blazor cascading values and parameters
This article explains how to flow data from an ancestor Razor component to descendent components. Cascading values and parameters provide a ...
Read more >
Cascading values and EventCallback in Blazor with layout ...
I'd create a state class and cascade that class to any child that wants to use it, by wrapping the @Body and the...
Read more >
Is there a way to handle a click event in a child component ...
I tried to use a cascading value as you suggested within my parent component and passing it to the child but unfortunately it's...
Read more >
Blazor – 4 DynamicComponent Examples – ASP.NET Core 6
When we want to send a message from a child component to a parent component, we usually use events with a parameter of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found