Blazor Components Flashcards

1
Q

How to write component names?

A

Should be written in PascalCase.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What syntax does the Blazor components use?

A

It uses the Razor syntax.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to create the most simple component as possible?

A

Just extract the html and place in a .razor file. Then use it in the place you extracted the HTML.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the “App” component and on which server deployment schema is it used?

A

The app component is the root of any blazor app, either WASM or serverside blazor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does the Blazor component structure look like?

A

Components within components within components and so on..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Would an access to the filesystem be equal on blazor wasm and server side blazor?

A

No… they differ. On server side it would open the server folder.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Are the structure and feature equal on both blazor deploy model?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between a razor component and a razor page?

A

Structurally none. The page has the @page instruction indicating the route.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to create a library containing razor components?

A

By using a razor class library.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does the “razor shared lib” template contain?

A

wwwroot folder, an _imports and an example component.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to use a library in the project?

A

Create a reference to the component lib project and adding a @using statement in the _imports.razor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Does visual studio/vscode generate a class for each razor file? What is its extension and what is the base class it inherits?

A

Yes. Every razor file generates a razor.g.cs that has a class that inherits from ComponentBase.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When moving the code from the razor file to a dedicated c# file, which class do we need to inherit? What needs to be done in the razor file?

A

ComponentBase. It is necessary to define that the razor file @inherits from the class that inherits from component base.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Is there another way to moving the source code to another file other than inheriting from component base?

A

Yes. with partial classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Where are the default event handlers (such as @onClick) stored?

A

in the ms.aspnetcore.components.web

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the “diff mechanism” that is applied in Blazor?

A

It means that changes to the html will be applied without a dom refresh.

17
Q

What to do when my component needs to receive values from another component?

A

It is necessary to declare a public property (w/ get and setters) and data annotate it with [Parameter]

18
Q

What is the effect of having a public prop called ChildContent with the RenderFragment type?

A

Anything inside the component calling will be rendered.

19
Q

What are the two ways of passing a parameter to a component?

A

Via URL or via [Parameter]

20
Q

What happens when the HTML that hold the component is removed from the HTML? How to prevent it from getting destroyed?

A

It gets destroyed. You can prevent it from being destroyed by hiding the HTML element instead.

21
Q

How to make sure the diff mechanism will be able to know automatically if something has changed in the razor component and where to update? When to use it?

A

By using the @key property. Then assign an unique identifier to it, so that blazor won’t loose track and have to re-render everything. Use it when you plan to update the content of a component that is rendered based on a list (basically for all for each).

Note:
The key can also be assigned to a razor component itself. (looks so much better this way)

22
Q

What is ONE-way bind? How to do it using the razor syntax?

A

One-way binding is a way to update the UI based on the property changes (changes in the prop will be reflected on the UI). Can be done by simply @myProp in the html element.

23
Q

What is TWO-way binds: How to do it using the razor syntax? When the bind is fired?

A

Changes in the source code property or in the UI will reflect in each other. Can be achieved by @bind=”myProp” in the HTML element. It is fired when user exits the field/element.

24
Q

Should we use bindings when we want to do extra computations in the fields OnChange event?

A

No. You have to manually implement this event.

25
Q

How to notify the parent component when the child component is changed?

A

Via EventCallback OnMyEventHappens in the component that is going to be watched. Then the parent event needs to subscribe to this callback.

26
Q

How to create a custom bind on the razor syntax, such as @Bind-Name?

A

You need to create an EventCallback with the name NameChanged.

27
Q

What is the concept of cascading values? How to declare it? Will blazor monitor the value of these values and trigger updates, can it be disabled?

A

It is when you define a variable to be cascaded to the child components. Declared using CascadingValue value=”myvar” and on the child component as [CascadingParameter]. Yes, blazor will monitor them - disabled by IsFixed=True.

28
Q

What is attribute splatting?

A

Defines a dictionary of string, object and then allow defining element properties inside, such as “size”, “50”

29
Q

How to reference an object inside a component?

A

By using @ref.