|
1 | 1 | ---
|
2 | 2 | title: Action Parameters (Callbacks)
|
3 | 3 | sidebar_position: 4
|
| 4 | +tags: [Components, Actions] |
| 5 | +keywords: [Components, Actions, Action Parameter, Callbacks] |
| 6 | +description: Learn how to add action parameters or callbacks to custom components. |
4 | 7 | ---
|
5 | 8 |
|
6 | 9 | # Action Parameters (Callbacks)
|
@@ -33,13 +36,13 @@ This makes the *image upload component* component reusable, as it doesn't need t
|
33 | 36 |
|
34 | 37 | ## Adding Callbacks
|
35 | 38 |
|
36 |
| -Let’s continue with our previous example (image upload component) and see how to add callbacks on it: |
| 39 | +Let’s continue with our previous example (*image upload component*) and see how to add callbacks on it: |
37 | 40 |
|
38 | 41 | ### Creating a Callback Parameter
|
39 | 42 |
|
40 | 43 | In order to create a component that will execute a callback, you must create a component with a parameter of **Type** **Action**. You can create an action parameter called `uploadAction`, which represents the action that will be executed after the image is uploaded.
|
41 | 44 |
|
42 |
| -When you create an action parameter, you can also specify parameters that will be passed into the action. For this example, the action that will be executed will likely need to know the uploaded image URL to process it further, such as resizing and compressing the image, updating it in the database, and refreshing the profile picture. So, you can specify an action parameter called `uploadedURL`. |
| 45 | +When you create an action parameter, you can also specify parameters that will be passed into the action. For this example, the action that will be executed will likely need to know the uploaded image URL to process it further. So, you can specify an action parameter called uploadedURL. |
43 | 46 |
|
44 | 47 | Now, the page or component that uses this button can utilize this parameter in its own action flow. An example of this is shown below.
|
45 | 48 |
|
@@ -141,34 +144,30 @@ You can access the value passed to the callback by navigating to the **Set Varia
|
141 | 144 | </div>
|
142 | 145 | <p></p>
|
143 | 146 |
|
144 |
| -:::tip |
145 | 147 |
|
146 |
| -Now that we have an image upload component with action parameters, it can be reused across different pages or contexts, as it relies on the parent to define the post-upload logic. For example, the same component can be used to upload an image while posting reviews for a product, eliminating the need to create a separate component for this functionality. |
| 148 | +Now that we have an *image upload component* with action parameters set up, it can be reused across different pages or contexts, as it relies on the parent to define the post-upload logic. For example, the same component can be used to upload an image while posting reviews for a product, eliminating the need to create a separate component for this functionality. |
147 | 149 |
|
148 | 150 | 
|
149 | 151 |
|
150 |
| -::: |
151 | 152 |
|
152 | 153 | ## More Examples
|
153 | 154 |
|
154 |
| -Let's see some more examples of adding action parameters (callbacks) to component to solidify understanding and use it in real-world scenarios. |
| 155 | +Let's see some more examples of adding action parameters (callbacks) to deepen the understanding and use it in real-world scenarios. |
155 | 156 |
|
156 |
| -### Example 1: Dynamic Dialog Components |
| 157 | +### Example 1: Dynamic Dialog Component |
157 | 158 |
|
158 | 159 | Let’s take another example of a reusable dialog component that uses callbacks to handle context-specific actions like confirming a deletion, logging out, or saving data. In one context, "Yes" deletes an item. In another, it logs out a user.
|
159 | 160 |
|
160 |
| -Here the dialog component can execute different actions based on the context in which it's used. The specific logic for each action is defined by the parent component or page using the dialog. The dialog itself does not need to know the specifics of what should happen—it simply executes the callback passed to it. |
161 |
| - |
162 |
| -[image] |
| 161 | +The specific logic for each action is defined by the parent component or page using the dialog. The dialog itself does not need to know of what should happen—it simply executes the callback passed to it when users click on the "Yes" button. |
163 | 162 |
|
164 |
| -[how to] |
| 163 | + |
165 | 164 |
|
166 |
| -### Example 2: Custom Navigation Bar |
| 165 | +### Example 2: Custom Navigation Bar in Super App |
167 | 166 |
|
168 |
| -[info] |
| 167 | +Using Action Parameters to build a Custom Navigation Bar in a Super App is an excellent way to create a dynamic, reusable, and modular navigation solution. A **Super App** typically hosts multiple mini-apps or features, each requiring specific navigation logic. Action Parameters allows you to define navigation behavior dynamically, depending on the active context, making it perfect for this scenario. |
169 | 168 |
|
170 |
| -[image] |
| 169 | +Here, the navigation bar doesn’t require hardcoded routes. Instead, the navigation logic can be customized for each mini-app, allowing the navigation bar to remain focused solely on its UI role. |
171 | 170 |
|
172 |
| -[how to] |
| 171 | +For example, in an **ecommerce mini-app**, the home button navigates to the product listing page, while the main (middle) button opens the shopping cart. In contrast, in a **cab booking mini-app**, the home button navigates to the dashboard, and the main (middle) button opens the quick booking page. |
173 | 172 |
|
174 |
| -## Best practices |
| 173 | + |
0 commit comments