Closed lonix1 closed 1 year ago
Any time you inject IState<Whatever>
it has an event on it that you can subscribe to. Make sure you unsubscribe when your component is disposed.
Ok I didn't know where that event was defined, thanks for that!
Just to be sure I understood, this is what I have:
@inherits MudComponentBase @* not FluxorComponent *@
@implements IDisposable
...markup...
@code {
[Inject] private IState<MyState> State { get; set; } = default!;
protected override void OnInitialized() {
base.OnInitialized();
State.StateChanged += HandleStateChanged;
}
public void Dispose() => _state.StateChanged -= HandleStateChanged;
private void HandleStateChanged(object? sender, EventArgs e) => InvokeAsync(StateHasChanged);
}
Is that what you referred to?
That is spot on!
You could also use this to subscribe to all state properties in one go and dispose the IDisposable it returns when finished.
https://github.com/mrpmorris/Fluxor/blob/master/Source/Lib/Fluxor/StateSubscriber.cs#L30
That is spot on!
You could also use this to subscribe to all state properties in one go and dispose the IDisposable it returns when finished.
https://github.com/mrpmorris/Fluxor/blob/master/Source/Lib/Fluxor/StateSubscriber.cs#L30
Can you give me an example of how to correctly subscribe to an IState
I've a component derived from a class other than
FluxorComponent
.The docs state:Does someone have an example of what that looks like?