ZumoKit State
ZumoKit keeps track of current state centralized state object. This allows to easily react to state changes.
Get Initial State
ZumoKit state can be accecced at any time from ZumoKit
instance:
State state = zumoKit.getState();
ZKState *state = [zumoKit getState];
const state = ZumoKit.state;
State contains all information on currently authenticatated user (see View User Data) and helper data described in Utilities & Helpers. For full details on State
object see reference (Android / iOS / React Native).
Listen to State Changes
State listener in Android and iOS SDK must implement state listener interface. React Native SDK does not require this step.
public class MyStateListener implements StateListener {
@Override
public void update(State state) {
// Do something with state
}
}
@interface MyStateListener : NSObject <ZKStateListener>
- (void)update:(nonnull ZKState *)state // Do something with state in implementation
@end
// Step not required for React Native ZumoKit SDK
Call addStateListener
on ZumoKit
instance to add state listener.
MyStateListener listener = new MyStateListener();
zumoKit.addStateListener(listener);
MyStateListener *listener = [MyStateListener alloc];
[zumoKit addStateListener:listener];
const subscription = ZumoKit.addListener((state) => {
// Do something with state
});
Listener is called each time ZumoKit state changes.
Save listener (or subscription reference in case of React Native) reference to remove remove listener later.
Remove State Listener
Once listener is not required anymore, listener should be removed with removeStateListener
method. Use reference from previous step to remove listener. In React Native listener should be removed when a component is unmounted.
zumoKit.removeStateListener(listener);
[zumoKit removeStateListener:listener];
componentWillUnmount() {
subscription.remove();
}