Skip to content

Intro to Reusable Functions

Reusable functions are custom JavaScript functions that can be defined once and called from multiple places throughout your Wized project.

They provide a powerful way to encapsulate logic, reduce code duplication, and make your project more maintainable by centralizing commonly used functionality.

Key Benefits

  • Code Reusability: Write once, use everywhere - functions can be called from global events, element events, workflow nodes, and other functions
  • Props Support: Functions can accept props (parameters) to make them flexible and adaptable to different use cases
  • Maintainability: Update logic in one place and have it automatically apply everywhere the function is used
  • Organization: Keep your code organized by grouping related functionality into reusable functions
  • Efficiency: Reduce the amount of duplicate code across your project

Where Can You Use Functions?

Reusable functions can be invoked from:

  • Global Events - Run functions in response to page-level triggers
  • Element Events - Execute functions when users interact with elements
  • Workflow Nodes - Call functions as part of a workflow sequence
  • Other Functions - Build complex logic by composing multiple functions

Function Modes

When configuring actions in events or workflows, you have two options:

  1. Inline Function - Write code directly in the action (traditional approach)
  2. Select Function - Choose a pre-defined function and pass values to its props

This flexibility allows you to use inline code for simple, one-off logic while leveraging reusable functions for shared functionality.