10.3.0 • Published 4 years ago

@alexseitsinger/react-render-controller v10.3.0

Weekly downloads
61
License
BSD-2-Clause
Repository
github
Last release
4 years ago

RenderController

Renders a component after its data has been loaded. Expects the use of @alexseitsinger/redux-locations.

Installation

yarn add @alexseitsinger/react-render-controller

Props

NamePurposeRequiredDefault
controllerNameThe unique name of this controller.Yesundefined
targetsAn array of target objectsYesundefined
renderFirstThe function used to render output before the data loading is attemptedNoundefined
renderWithThe function used to render the output once the data has been loadedNoundefined
renderWithoutThe function used to render the output when data loading failed to produce non-empty resultNoundefined
renderBothThe function used to render instead of both renderWith and renderWithoutNoundefined
skippedPathnamesAn array of objects that unloading should be skipped for.Noundefined

Shapes

Target
{
  name: String,
  data: Array|Object,
  getter: Function,
  setter: Function,
  empty: Object|Array,
  cached: Boolean,
}
Skipped Pathname
{
  url: String,
  reverse: Boolean,
}

Example

In app root

import { RenderControllerProvider } from "@alexseitsinger/react-render-controller"

const App = ({ store, routerHistory }) => (
  <RenderControllerProvider
    onRenderFirst={() => <LoadingScreen />}
    onRenderWithout={() => <FailedScreen />}
    getPathnames={() => {
      const state = store.getState()
      const { current, last } = state.locations
      return {
        lastPathname: last.pathname,
        currentPathname: currentPathname,
      }
    }}>
    <Provider store={store}>
      <ConnectedRouter history={routerHistory}>
        <Route path={"/"} exact component={IndexPage} />
      </ConnectedRouter>
    </Provider>
  </RenderControllerProvider>
)

Within a page component

import { RenderController } from "@alexseitsinger/react-render-controler"

const HomePage = ({
  dates,
  getDates,
  setDates,
}) => (
  <RenderController
    controllerName={"home-page-dates-controller"}
    targets={[
      {
        name: "dates",
        data: dates,
        getter: getDates,
        setter: setDates,
        empty: {},
        cached: true,
      },
    ]}
    skippedPathnames={[
      {
        url: "/about",
        reverse: true,
      },
    ]}
    renderWith={() => (
      <div>
        {Object.keys(dates).map(key => (
          <div key={"fdsfsd"}>{key}</div>
        ))}
      </div>
    )}
  />
)
10.3.0

4 years ago

10.2.0

4 years ago

10.1.0

4 years ago

10.0.0

4 years ago

9.2.3

4 years ago

9.2.1

4 years ago

9.2.0

4 years ago

9.0.1

4 years ago

9.0.0

4 years ago

8.0.0

4 years ago

7.4.1

4 years ago

7.4.0

4 years ago

7.3.4

4 years ago

7.3.3

4 years ago

7.3.2

4 years ago

7.3.1

4 years ago

7.3.0

4 years ago

7.2.0

4 years ago

6.6.0

4 years ago

6.5.3

4 years ago

6.5.2

4 years ago

6.5.0

4 years ago

6.3.0

4 years ago

6.3.2

4 years ago

6.3.1

4 years ago

6.2.0

4 years ago

6.1.1

4 years ago

6.1.0

4 years ago

5.8.1

5 years ago

5.7.0

5 years ago

5.1.0

5 years ago

4.1.0

5 years ago

2.18.1

5 years ago

2.18.0

5 years ago

2.16.0

5 years ago

2.13.0

5 years ago

2.10.1

5 years ago

2.10.0

5 years ago

2.8.0

5 years ago

2.7.0

5 years ago

2.6.4

5 years ago

2.6.3

5 years ago

2.6.0

5 years ago

2.5.0

5 years ago

2.4.0

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago