Skip to content
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

Question about component #2

Closed
gptucci opened this issue Nov 5, 2019 · 2 comments
Closed

Question about component #2

gptucci opened this issue Nov 5, 2019 · 2 comments

Comments

@gptucci
Copy link

gptucci commented Nov 5, 2019

Hi
Excuse me for stupid question
I have a blazor page that contains 3 Blazor-components: one display all items, another one is a form to insert new items and the latest show the counter (number of items)
I want use BlazorState.Redux for all the stuff and to share the state (item list)
Can you help me to structure the code correctly?
Possible Solutions

  1. Create a single connected container component that use 3 method Get()
    RenderFragment GetComponent01
    RenderFragment GetComponent02
    RenderFragment GetComponent03

  2. Create 3 separate connected component and in the master page
    @page "/counter"

@CounterCmp
@CounterCmp1
@CounterCmp2

@code {
RenderFragment CounterCmp = CounterConnected.Get();
RenderFragment CounterCmp1 = Counter1Connected.Get();
RenderFragment CounterCmp2 = Counter2Connected.Get();

}

  1. ????

Really tnx and excuse me for my question that which I imagine is stupid

@BerserkerDotNet
Copy link
Owner

Hi @gptucci, sorry for a late reply, somehow I don't get notifications when issues are created :(.

First of all, there is no such thing as a stupid question, there are only stupid answers ;)

As to your question, the general rule is there should be one connected component for one presentational component. For this reason, I would recommend option 2. It is the one that separates concerns best. That is each component is a separate connected component and responsible for its operation. In your example, you would not want to mix logic related to the form with the logic related to the list as those are two separate things. However, there is nothing wrong with the form utilizing the same bits of the state as the list does. That is all done in the connected's component MapStateToProps method. There, you get the whole state object and it is this method responsibility to extract/transform useful bits for its particular component.

Let me know if it is not clear, I can try fixing a small example :)

@gptucci
Copy link
Author

gptucci commented Nov 19, 2019

really tnx
I think that all is clear
Tnx

@gptucci gptucci closed this as completed Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants