Observing Flows

Introduction

As described on the serialising flows, you should be able to serialise a Flow to a ConanState that suits you, and then leverage all the features of the Conan State to observe it.

We have though some mechanisms to provide you with a shortcut when observing flows

As of v1.0 we only have hooks, but we are planning to add more shortcuts to observe directly flows without having to serialise them

Hooks

useFlow

useFlow<AuthenticationState,AuthenticationFlow>(
authentication$F,
setState,
(status, previousState) => ({
...previousState,
current: status.name,
})
);

This hook receives

  • a flow

  • the method to set the state for this component

  • a function that returns the new state and that takes

    • the status information that has just been updated

    • the previous state

useFlowStatus

useFlowStatus<AuthenticationState, AuthenticationFlow,"authenticating">(
authentication$F,
"authenticating",
setState,
(status, previousState) => ({
...previousState,
currentUser: status[0]
}
));

This hook receives

  • a flow

  • the name of the status to subscribe to

  • the method to set the state for this component

  • a function that returns the new state and that takes

    • the state information that has just been updated

    • the previous state

To see an example of hooks, check our demo Authentication