Connect

The data-fetching decorator for Lore

singleton

This blueprint is useful when you know there will only ever be a single resource returned by an API endpoint. While rare, this exists in endpoints like /user or /profile that return an object that describes the current user.

Usage

Example usage is below:

import { connect } from 'lore-hook-connect';

connect((getState, props) => {
  return {
    tweet: getState('currentUser')
  };
})

When invoked, this blueprint will look in the currentUser reducer, and return whatever it finds. If nothing exists, it will invoke the currentUser action.

This blueprint does not accept any paramters, because it assumes there will only ever be a single resource provided. So it's "give me THE resource", and not "give me a resource WHERE some condition is true".

Blueprint

export default {

  getPayload: function(reducerState, params) {
    return reducerState;
  },

  callAction: function(action, params) {
    return action().payload;
  }

};