You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ff-concepts/adding-customization/code-file.md
+62-14Lines changed: 62 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -176,40 +176,88 @@ To create an instance of a custom class, open the **Set from Variable** dialog a
176
176
</div>
177
177
<p></p>
178
178
179
-
<!--:::tip[When You Don't Need an Instance]
179
+
## Using Custom Class
180
+
181
+
Once the custom classis added successfully, you can access its fields and methods in the Variable Dialog, call its methods in the Action Flow Editor, assign instances to state variables, pass them to page or component parameters, and use enum values in dropdowns or conditionals.
182
+
183
+
### Custom Class as Data Type
184
+
185
+
You can select your custom classas a Type for variables, state, or parameters, just like a [Custom Data Type](../../resources/data-representation/custom-data-types.md).
You can skip instance creation when everything in the class is `static`, meaning it's shared across all uses (like a utility class). For example, look at the classbelow:
191
+
You can use custom classfields to display values directly in the UI, and call its methods in variable dialogs to return a result.
You can also add your custom class’s methods directly within an Action Flow. For example, you can trigger the `markHelpful()` method when a user taps a “Mark as Helpful” button to update a field or increment the helpful count of a review.
198
+
199
+
## Using Static Classes
200
+
201
+
Sometimes, you just want to run a small piece of logic like formatting text or doing a calculation, without needing to set up anything extra. That’s when `static` data members are helpful. You can access static fields and methods without creating an instance of a class. You can think of them like tools that are always ready to use.
202
+
203
+
This approach is typically used for**stateless utility classes** where shared functionality is needed across the app. For example, look at the classbelow:
182
204
183
205
```jsx
184
206
class Utils {
185
207
static int square(int x) => x * x;
186
208
}
187
209
```
188
210
189
-
In such cases, you can directly access the classdata and methods via the **Set from Variable** menu.
211
+
The `Utils`classcontains a static method `square` that returns the square of a number without needing to create an object of the class.
Here are couple more examples to understand it better:
193
214
194
-
## Using Custom Class
215
+
- This `StringFormatter`classbelow provides reusable static methods to capitalize text, convert it to lowercase, or format it in snake_case.
195
216
196
-
Once the custom classis added successfully, you can access its fields and methods in the Variable Dialog, call its methods in the Action Flow Editor, assign instances to state variables, pass them to page or component parameters, and use enum values in dropdowns or conditionals.
You can select your custom classas a Type for variables, state, or parameters, just like a [Custom Data Type](../../resources/data-representation/custom-data-types.md).
static int roundOff(double value) => value.round();
242
+
}
243
+
```
244
+
245
+
:::warning
246
+
247
+
Static classes are powerful, but they should be used carefully. Overusingstatic methods can lead to less flexible code and potential issues, especially when the logic requires access to state or needs to evolve over time. Stick to static methods only when the logic is truly independent and doesn’t rely on instance-specific data.
248
+
249
+
:::
250
+
251
+
### Access Static Fields and Methods
252
+
253
+
You can access the staticclassdata and methods directly via the ****Set from Variable**** menu.
You can also add your custom class’s methods directly within an Action Flow. For example, you can trigger the `markHelpful()` method when a user taps a “Mark as Helpful” button to update a field or increment the helpful count of a review.
0 commit comments