Objective Redux

Redux made better, objectively.

useController

function useController<C>(controller: Controller|ModelConstructor<C>, selectorFn: (state: any) => any = (state: any): any => state): C|null

Gets a controller from the ObjectiveStore using hook.

Template Parameters

<C>
The type of controller that will be returned. This type is inferred and does not need to be specified in
TypeScript.

Parameters

controller: Controller|ModelConstructor<C>
The controller class of which an instance should be retrieved.

selectorFn: (state: any) => any = (state: any): any => state
A state mapping function used to determine if the component needs to re-render. Defaults to(state: any): any => state.

Returns

C|null
An instance of the provided controller or null if there is no ObjectiveStore instance in the components
context.

Examples

import React from 'react';
import { useController } from 'objective-redux';
import { SwitchStateController } from './switch-state-controller';

export function MyFunctionalComponent() {
  const switchStateController = useController(SwitchStateController);
  const { isOn } = switchStateController.getStateSlice();

  return <p>Switch is { isOn ? 'On' : 'Off' }</p>;
}