WP Interactivity API - Workshop

Prep for workshop

    Download local by flywheel
    Connect to wpengine
    Fetch ofw-dev
    visit /product-search/ and make sure its visible


Wordpress interactivity API documentation





Actions vs Callbacks

In the WordPress Interactivity API, the difference between actions and callbacks lies in their purpose and usage:
  • Actions: Define custom logic that can modify the state or trigger side effects. These are triggered by user events like button clicks or form submissions (e.g., updating the context state).
  • Callbacks: Get executed automatically whenever the context changes, reacting to state updates. They typically log or perform read-only operations, like logging values or updating the UI based on new state.
In short: actions modify the state, while callbacks respond to state changes.



State and Context

In the WordPress Interactivity API, both context and state store and manage data, but they differ in scope and usage:
  • State: Refers to the current value or status of a specific property in a local scope, typically tied to a component or action. It can be changed by actions (e.g., state.text).
  • Context: A shared object accessible across multiple components and actions. It provides a way to manage and pass data globally without relying on props.
In essence, state is local to a component, while context is global and shared across components.




Useful videos

  •  https://www.youtube.com/watch?v=49_XlQJYztA 
  •  https://www.youtube.com/watch?v=NssaJLvz7bo 



Our workshop:

Passcode: 1+yd5iW5